const _this = this 就是为了解决匿名函数的指向问题而写的

252 阅读1分钟

const _this = this 就是为了解决匿名函数的指向问题而写的 其实很简单,注意const _this = this 的位置

    var myobj={
      a : 10,
      myfun : function(){
        const _this = this
        return function(){
          console.log(_this.a);
      }
    }
    }
    myobj.myfun()//10
    
  </script>
————————————————