【发布时间】:2021-12-02 14:12:59
【问题描述】:
我已经搜索并阅读了这个问题很长时间,但仍然无法理解。 所以在一个 React 类组件中,你会写这样的方法:
class Test extends React.Component {
constructor(props){
super(props)
this.method = this.method.bind(this)
}
method() {
...
}
}
如果“this”默认没有绑定,为什么我们可以使用“this.method”呢? “this”在“this.method”和“bind.(this)”中是什么意思。它们是一样的吗?
这条线:this.method = this.method.bind(this) 真的让我很困惑。请帮我解释这一行中的 3 个“this”中的每一个。谢谢。
【问题讨论】:
标签: javascript reactjs class binding this