this作用域问题
var name = "the window"
var object = {
name: "my object",
getName:function(){
return function(){
return this.name;
}
}
}
alert(object.getName()());
结果:弹出 “the window”。
分析:
第一个 return 把 “ function(){ return this.name;} ” 抛出在window对象下,
第二个 return 又把 “this.name ” 抛出在window对象下,
所以这是的 this.name 就相当于 window.name 。

浙公网安备 33010602011771号