JS闭包

var name = "The Window";
var object = {
name: "My Object",
getNameFunc: function () {
return function () {
return this.name;
};
}
};
alert(object.getNameFunc()()); //The Window

最终返回 "The Window" 解析:

因为闭包的原因 this.name 获取不到 "My Object",因为 它是父类的 父类的 参数, 闭包只能获取到父类层的 参数
所以 最终调用的是 "The Window"

原文地址:https://www.cnblogs.com/sunzhenyong/p/3981967.html