【发布时间】:2020-04-29 19:52:35
【问题描述】:
我知道已经有一些关于这方面的线索,但我找不到真正的线索。
所以我的问题是,我应该始终使用绑定方法还是箭头函数?
2020年它们的优缺点是什么?根据我所读到的,我知道(至少在 2018 年)绑定方法具有更好的性能。
另一个问题:我是否应该只绑定函数,我通过单击在渲染方法中调用使用?
这里是一个小例子
constructor(super) {
props(super)
this.firstBind = this.firstBind.bind(this);
this.secondBind = this.secondBind.bind(this;
}
render() {
return (
<Button title="First Bind" onClick={this.firstBind} />
<Button title="First arrow" onClick={this.firstArrow} />
)
}
firstArrow = () => {
//some outout
}
secondArrow = async() => {
//fetch some data from a database and output it
}
secondBind() {
//some output
}
async secondBind() {
//fetch some data from a database and output it
}
我的目标是完全理解它。
非常感谢!
一月
【问题讨论】:
标签: react-native