如何在es6中使用箭头函数代替bind方法

Ame*_*gre 1 javascript ecmascript-6 reactjs

以前我用它在React JSX组件中调用我的方法,这个方法给我正确的输出

this.updateState.bind(this)
Run Code Online (Sandbox Code Playgroud)

但当我将上述声明替换为

() => this.updateState(...this)
Run Code Online (Sandbox Code Playgroud)

这不会给我输出它返回undefined

Kap*_*pil 5

你应该更换

 () => this.updateState(...this)
Run Code Online (Sandbox Code Playgroud)

 (...args) => this.updateState(...args)
Run Code Online (Sandbox Code Playgroud)

箭头函数从其父词法范围继承其上下文.
从箭头函数调用函数时,它继承自调用者的"this"引用.