由于this.handler.bind(this)
可以替换::this.handler
的,我怎么能代替this.handler.bind(this, 1)
使用::
?
在要附加处理程序以响应组件的情况下,我发现这很有用。例如:
handler(x) {
this.setState({counter: x})
}
<a onClick={this.handler.bind(this, 5)}>increment by 5</a>
我知道我可以使用_.curry
(破折号),但是在代码可读性方面几乎是相同的:
<a onClick={_.curry(::this.handler, 5)}>increment by 5</a>
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句