关于this对象

var name="the window";
var object={
	name:"my object",
	getNameFunc:function(){
		var that=this;
		return function(){
		    return that.name;
		}
			
	}
     };
alert(object.getNameFunc()())//my object

第二段代码

var name="the window";
var object={
        name:"my object",
        getNameFunc:function(){
            return function(){
                return this.name;
             }
        }
    };
    alert(object.getNameFunc()())//the window

这两段代码的对比就是申明了一个that变量转给this,this对象是根据当前位置,往上找,直到找到相关的对象停止寻找

 

原文地址:https://www.cnblogs.com/binmengxue/p/8559749.html