由React构造函数中bind引起的this指向理解(React组件的方法为什么要用bind绑定this)
由React构造函数中bind引起的this指向理解(React组件的方法为什么要用bind绑定this)
React文档源码
class Toggle extends React.Component {
constructor(props) {
super(props);
this.state = {isToggleOn: true};
// 为了在回调中使用 `this`,这个绑定是必不可少的
this.handleClick = this.handleClick.
原创
2020-05-29 14:29:36 ·
1233 阅读 ·
0 评论