根据作用域链的原理,最后this.name不应该在object里面找吗?
var name = "The Window";
var object = {
name : "My Object",
getNameFunc : function(){
alert("My Object "+this.name); //MyObject
return function () {
alert("The Window "+this.name);
return this.name;//This Window
}
}
};
你这段代码其实没有必要用
作用域链
来解释函数体内部的this指向是根据函数调用者来决定的。
我完善了一下你的代码,你应该能理解了。