javascript绑定确实适用于字典中的函数

javascript绑定确实适用于字典中的函数,javascript,ecmascript-6,Javascript,Ecmascript 6,所以我在字典里有一个函数 const Dict = { func : () => { console.log(this); } } class A { constructor() { this.fun = Dict.func.bind(this); } } const a = new A(); a.fun(); 这给了我未定义的,我希望这是a 如果我将函数移出字典,这个绑定似乎可以工作。为什么bind不能与dictiona

所以我在字典里有一个函数

const Dict = {
    func : () => {
       console.log(this);
    }
}

class A {
    constructor() {
        this.fun = Dict.func.bind(this);
    }
}

const a = new A();
a.fun();
这给了我未定义的,我希望这是
a


如果我将函数移出字典,这个绑定似乎可以工作。为什么bind不能与dictionary一起使用?

创建一个函数作为属性,而不是使用arrow函数,bind不能与arrow一起使用

const Dict = {
  func() {
    console.log(this);
  }
}

class A {
  constructor() {
    this.fun = Dict.func.bind(this);
  }
}

const a = new A();
a.fun();

Function.prototype.bind
不适用于带有箭头函数的
this