问题描述
我是初学者,目前正在 Codecademy 平台上学习 ReactJS。我需要一点帮助才能理解下面显示的示例代码。
class Example extends React.Component {
constructor(props) {
super(props);
this.state = { weather: 'sunny' };
this.makeSomeFog = this.makeSomeFog.bind(this);
}
makeSomeFog() {
this.setState({
weather: 'foggy'
});
}
}
我注意到那里有一条奇怪的线:
this.makeSomeFog = this.makeSomeFog.bind(this);
在课程部分,有解释说:
“这一行是必要的,因为 makeSomeFog() 的主体包含单词 this。”
你能帮我理解一下这意味着什么吗? 谢谢!
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)