Correct implementation of the Maybe monad in JavaScript