I noticed a weird thing in javascript. Consider the below:
var fn = ''.toUpperCase.call
console.log(typeof fn); // "function"
fn(); // Uncaught TypeError: `fn` is not a function
The above was executed on my Chrome's Developer Console. Version is 43.0.2357.81 m
.
The typeof
operator clearly shows that fn
is a function, but the error suggests otherwise.
I've noticed that Function.apply
shows at least some meaningful error message.
So, when is a function, not a function?
See Question&Answers more detail:os