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下面是我自己運(yùn)行的代碼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()());
}
JavaScript關(guān)于閉包的運(yùn)行機(jī)制的問題,運(yùn)行w3cschool的代碼,結(jié)果出現(xiàn)問題
aluckdog
2018-07-16 11:26:47