12
本周末我掠夺了一些最近的反应回购,并且我遇到了一个使用ES6类语法的组件组合的例子,它有点像这样。神秘的语法onClick = {:: this.submit}
class MyThing extends Component {
constructor(props) {
super(props)
this.state = {something: 'the thing'}
}
submit() {
// do stuff
}
render() {
<div>
<button onClick={::this.submit}>Fire Submit</button>
</div>
}
}
通知代替this.submit.bind(this)
它的作品,我不能对这个功能在任何地方找到文档,我觉得自己像一个疯狂的人::this.submit
,这是什么onClick={::this.doSomethingInsideRenderWithoutDotBind}
语法打来电话,我在哪里可以阅读更多关于它?
https://github.com/zenparsing/es-function-bind – Quentin
@Quentin就是这样!你很棒,非常感谢。我会接受这个答案,在你的闲暇时间。 – James
请记住,这是一个阶段0的功能,这意味着要实现标准化还有很长的路要走。有趣的知道,但最好避免在你自己的代码。 –