onMomentumScrollEnd={
(e)=>this.onAnimationEnd(e)
}
和
onScrollBeginDrag={
this.onScrollBeginDrag
}语法为什么不相同 是传参的原因吗
(e)=>this.onAnimationEnd(e)这个是什么意思 属于什么语法 是ES6=>这个吗
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
你需要提出这是在react中jsx写法,要不然你的两段代码是不能用的。。。估计有两个downvote也是因为这个原因。。。
应该这么写才能表清楚。
<Component onMomentumScrollEnd={(e)=>this.onAnimationEnd(e)} onScrollBeginDrag={this.onScrollBeginDrag} />现在根据上面代码讲一下:
onMomentumScrollEnd={(e)=>this.onAnimationEnd(e)}代表了把(e)=>this.onAnimationEnd(e)当作onMomentumScrollEnd的值传给下级组件(e)=>this.onAnimationEnd(e)是ES6的箭头函数写法,而且箭头函数会自动绑定this,等同于onScrollBeginDrag={this.onScrollBeginDrag}就是把this.onScrollBeginDrag作为onScrollBeginDrag的值传给子组建