箭头函数是 ES6 标准的新特性。如果您需要使用箭头函数,则无需将任何事件绑定到this
。这里,this
的范围是全局的,不限于任何调用函数。因此,如果使用箭头函数,则无需在构造函数中绑定this
。它也被称为“胖箭头”(=>)函数。
//General way
render() {
return(
<MyInput onChange={this.handleChange.bind(this) } />
);
}
//With Arrow Function
render() {
return(
<MyInput onChange={ (e) => this.handleOnChange(e) } />
);
}