var myObject = {foo: "1",func: function() {var foo = "2";var self = this;console.log(this.foo); console.log(self.foo); return function() {console.log(this.foo); console.log(self.foo); };}
};
(myObject.func())();
func()函数被myObject调用,因此里面的this指向myObject,之后返回的函数,立即执行,this指向window,但由于self之前已经保存过了this,因此self的指向是myObject
1 1 undefined 1
var foo = {bar(){(function(){console.log(this)})()}
}
foo.bar()
bar中的立即执行函数,没有被其他的对象显示调用,因此this指向window
window