this
,或者只需在构造函数中应用箭头函数。请注意,在我的项目中我只能使用ES6语法。class Test extends React.Component{
constructor(props) {
super(props);
this.doSomeThing = this.doSomeThing.bind(this);
}
doSomething() {}
}
2.class Test extends React.Component{
constructor(props) {
super(props);
this.doSomeThing = () => {};
}
}
这两种方法的优缺点是什么?谢谢。