Why does an immediately invoked method return the window
object as this
,
var o = {};
o.foo = function () {
console.log(this);
}(); //Window {…}
but when executed later, the method returns the object o
(as I would have expected in both cases)?
var o = {};
o.foo = function () {
console.log(this);
}
o.foo(); //Object {foo: function}