var name = "the window"; var object = function (){ this.name = "My object"; this.getNameFunc = function(){ return function (){ alert(this.name); return this.name; }; } };var aa = new object(); var bb = aa.getNameFunc(); //getNameFunc返回的是一个匿名function,也就是说: bb = function (){ alert(this.name); return this.name; }; var cc = bb(); //这时,bb内部的this为window,因此alert的是window.name //window.name被第一句var name给覆盖了,所以是"the window" alert(cc);//alert(window.name);
var name = "the window";
var object = function (){
this.name = "My object";
this.getNameFunc = function(){
return function (){
alert(this.name);
return this.name;
};
}
};var aa = new object();
var bb = aa.getNameFunc();
//getNameFunc返回的是一个匿名function,也就是说:
bb = function (){
alert(this.name);
return this.name;
};
var cc = bb();
//这时,bb内部的this为window,因此alert的是window.name
//window.name被第一句var name给覆盖了,所以是"the window"
alert(cc);//alert(window.name);