箭头函数和 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)}
我在看这个 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)}