about this

var name="window name";
              var obj={
                  name:"obj name",
                  getNameFunc:function(){
                      //this 是object
                      return function(){
                          //this 是window
                          return this.name;
                      }
                  }
              }
              console.log(obj.getNameFunc()())//window name
var name="window name";
              var obj={
                  name:"obj name",
                  getNameFunc:function(){
                      //this 是object
                    var self=this;
                      return function(){
                          //this 是window
                          return self.name;
                      }
                  }
              }
              console.log(obj.getNameFunc()())//obj name
var name="window";
var obj={
  name:"lilei",
  f:function(){
     return function(){
       return this.name;
     }
   }
};
obj.f()();//"window"
var obj={
  name:"lilei",
  f:function(){
     return this.name;
   }
};
obj.f();//"lilei"
var name="window";
var obj={
  name:"lilei",
  f:function(){
     return this.name;
   }
};
obj.f();//lilei

 

posted @ 2016-09-01 17:43  逗伴不是瓣  阅读(271)  评论(0编辑  收藏  举报