Learning about this in JavaScript. I am confused about the scope of this inside iife. Why this points to window object inside iife? This should points to myObj because it is inside myObj.
window.foo = "bar1";
var myObj = {
foo: "bar2",
func: function() {
var self = this;
console.log(this.foo + ", " + self.foo);
(function xx() {
console.log(this.foo + ", " + self.foo)
}());
}
}
myObj.func();
Output -
bar2, bar2
bar1, bar2
I am concerned about bar1 in second line.