固定内层函数的 this

index.js

const obj = {
  foo() {
    console.log(this); // obj
    const self = this;
    const bar = (function () {
      console.log(self); // obj
    })();
  },
};

obj.foo();

posted on 2021-09-10 09:40  aisowe  阅读(23)  评论(0)    收藏  举报

导航