How come the code below doesn't work?
var x = {};
x.a = alert;
x.a('asdf'); // TypeError: Illegal invocation
How come the code below doesn't work?
var x = {};
x.a = alert;
x.a('asdf'); // TypeError: Illegal invocation
Because the internals of the alert
function requires that the value of this
be window
.
x.a.call(window,'asdf');
… will work.