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
你应该更换
() => this.updateState(...this)
Run Code Online (Sandbox Code Playgroud)
同
(...args) => this.updateState(...args)
Run Code Online (Sandbox Code Playgroud)
箭头函数从其父词法范围继承其上下文.
从箭头函数调用函数时,它继承自调用者的"this"引用.
| 归档时间: |
|
| 查看次数: |
82 次 |
| 最近记录: |