In this example, I am passing foo.bar
to an IIFE, which returns executing 1st-argument. I am passing a function which gets executed, returning this
(pointing to window).
So, the return is stored in a
which should be window
. Then, why it is returning me the argument itself?
var foo = {
bar: function() {
console.log("***", this);
return this;
},
baz: 1
};
var a = (function(){
console.log("window?", this===window);
return arguments[0]();
})(foo.bar);
console.log("a", a);