码迷,mamicode.com
首页 > 其他好文 > 详细

about this

时间:2016-09-01 18:33:17      阅读:173      评论:0      收藏:0      [点我收藏+]

标签:

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

 

about this

标签:

原文地址:http://www.cnblogs.com/-walker/p/5830755.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!