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 。

 

posted @ 2015-05-13 23:38  G-lin  阅读(88)  评论(0)    收藏  举报