关于闭包的一些学习思考

来源:互联网 发布:中小企业破产数据 编辑:程序博客网 时间:2024/05/27 03:30
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;