console.log("0"); var name = "The Window"; console.log("1"); var object = { name: "My Object", getNameFunc: function () { return function () { console.log(this.name); return this.name; }; } }; console.log("3"); console.log(object.getNameFunc()()); }
这是原代码地址:https://www.w3cschool.cn/jsnote/jsnote-closure.html
下面是我自己运行的代码
function JSPfunction003() { console.log("0"); var name = "The Window"; console.log("1"); var object = { name: "My Object", getNameFunc: function () { return function () { console.log(this.name); return this.name; }; } }; console.log("3"); console.log(object.getNameFunc()()); }
相关分类