美文网首页
this 指向

this 指向

作者: zhulichao | 来源:发表于2020-08-05 10:16 被阅读0次
    var myObject = {
      foo: 'bar',
      func: function() {
        var self = this;
        console.log('outer func:this.foo = ', this.foo); // bar
        console.log('outer func:self.foo = ', self.foo); // bar
        (function(){// 立即执行函数,没有 this
          console.log('inner func:this.foo = ', this.foo); // undefined, this 指向 window
          console.log('inner func:self.foo = ', self.foo); // bar
        }());
      }
    };
    myObject.func();
    

    相关文章

      网友评论

          本文标题:this 指向

          本文链接:https://www.haomeiwen.com/subject/lrxphktx.html