var name = "The Window";
var object = {
name : "My Object",
getNameFunc : function(){
return function(){
return this.name;
};
}
};
alert(object.getNameFunc()());
var name = "The Window";
var object = {
name : "My Object",
getNameFunc : function(){
var that = this;
return function(){
return that.name;
};
}
};
alert(object.getNameFunc()());
知道闭包是要在函数外部读取内部的变量,但是这个代码还是不咋理解啊= =
既然你提到了闭包,那你看看这段代码,自己先思考下,再运行,希望帮到你~