关于闭包的一些学习思考

var name="The windows";
var object={
name:"My object",
getNameFunc:function one (){
    return function two (){
    return this.name;
    };
}
};
console.log(object.getNameFunc()())//The windows

this.name中的this指的是function two(),而function two()已经被function one()返回出来,所以跳出object{}的范围,this.name=The windows;

var name="The windows";
var object={
name:"My object",
getNameFunc:function one (){
    //return function two (){
    return this.name;
    //};
}
};
console.log(object.getNameFunc())//My object

this.name中的this指的是function one(),而function one()仍在object{}的作用域中,this.name=My object;

你可能感兴趣的:(HTML+CSS,学习体会)