deceze's answer is correct, I just want to explain it from a different point of view.
Your fn
is a reference to Function.prototype.call
which needs to be called with a function as its this
reference, in this case, the context for call
is String.prototype.toUpperCase
, which was inherited through ''.toUpperCase
On top of that, String.prototype.toUpperCase
also has to be called with a specific context, the string to upper case.
Here's another way to code what you wanted that may help you understand what is going on.
var str = 'aaa';
var upper = ''.toUpperCase;
var fn = upper.call;
// Now we have to specify the context for both upper and fn
console.log( fn.call(function() { return upper.call(str)}) ); // AAA
In your example, fn()
is attempting to call call
but it's not specifying the context, which typically defaults to the window
object but in this case it just makes it undefined
, which triggers a weird error in Chrome (as you discovered), but Firefox is clearer about the problem,
TypeError: Function.prototype.call called on incompatible undefined