扫码关注官方订阅号
闭关修行中......
使用箭头函数的话,一般是就在那个位置写执行代码。而比如说已经有一个function定义好了,那还是用bind来做吧。
function
bind
或者你这里试试这样写
onClick={event=>this.handleClick(event)}
箭头函数是箭头函数,bind this 是bing this,是两个东西。
题主的“如何使用箭头函数改写从而省略这里的 bind(this)”是错误的。
省略this的优美方案是引入es7的:: 在 babel中把stage-0引入即可。
class MyComponent extends React.Component { render() { return ( <p> <input type="text" ref="myTextInput"/> //如何使用箭头函数改写从而省略这里的 bind(this) <input type="button" value="Focus the text input" onClick={() => {this.refs.myTextInput.focus()}}/> </p> ); } }
可以通通放到 constructor 里面绑定
微信扫码关注PHP中文网服务号
QQ扫码加入技术交流群
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
PHP学习
技术支持
返回顶部
使用箭头函数的话,一般是就在那个位置写执行代码。
而比如说已经有一个
function定义好了,那还是用bind来做吧。或者你这里试试这样写
箭头函数是箭头函数,bind this 是bing this,是两个东西。
题主的“如何使用箭头函数改写从而省略这里的 bind(this)”是错误的。
省略this的优美方案是引入es7的:: 在 babel中把stage-0引入即可。
可以通通放到 constructor 里面绑定