var name = "this windos";
var object = {
name : "my object",
getnamefunc : function () {
return function () {
return this.name;
};
}
};
var reslut = object.getnamefunc();
console.log(object.getnamefunc()());
console.log(reslut);
console.log(reslut.toString());
console.log(reslut());
console.log(object.name);
console.log(name);```
在看高程3 关于 this 在闭包中介绍
如上代码
我在终端用 node 跑范例代码 结果 浏览器 和 node 给出了不同的答案
在 node 7.7.2 结果
undefined
[Function]
function () {
return this.name;
}
undefined
my object
this windos
在 chrome 57.0.2987.98 (64-bit)
this windos
function () {
return this.name;
}
function () {
return this.name;
}
this windos
my object
this windos