Treating the bind method for JS functions as a value makes it behave unexpectedly when used in conjunction with both the ternary and short-circuit operators. Why does this happen?
I tried to make a utility function shorter by using the ternary operator, but it always resulted in Uncaught TypeError: Bind must be called on a function
.
So I tried this that worked just fine:
(Date.bind)(null)()
Nevertheless this did not:
(true && Date.bind)(null)()
Neither did this:
(true ? Date.bind : '')(null)()
As per the evaluation of those expressions I expected the same output on each one—a string value representing a date—but it just happened in the first one and the other ones resulted in the error Uncaught TypeError: Bind must be called on a function
.