箭头函数和 onChange

Arrow functions and onChange

我在看这个 React 教程,导师在 onChange prop 中传递了一个箭头函数,该函数又调用了实际的处理程序。这样做是为了使 this 关键字将引用处理程序所在的 class defined.But 我不明白 logic.I 理解为什么我们使用 bind 并将该方法定义为箭头函数来获取this 关键字指向方法属于 tom 的 class。但我不明白这个 one.Can 请有人解释它为什么有效

handler(e){

console.log(this.state.someVariable)
}
<input  type="text" onChange={(event)=>this.handler(event)}

如果您了解 JS 中的作用域,您就会了解 this 运算符。

好读物:

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/this

https://medium.com/backticks-tildes/understanding-hoisting-and-scoping-in-javascript-39ea7b41e31