我熟悉 Javascript 函数bind。但我不明白为什么在下面的 React.js 片段中this再次绑定到this。Has 与constructor有一些共同之处,因为根据使用情况,构造函数中的this可以具有不同的值?
预先感谢您的回复
class QuotesLibrary extends React.Component {
constructor(props) {
super(props);
this.search = debounce(this.search.bind(this), 300);
}
search(searchTerm) {
this.props.relay.setVariables({searchTerm});
}
render() {
return (
<div className="quotes-library">
<SearchForm searchAction={this.search} />
<div className="quotes-list">
{this.props.library.quotesConnection.edges.map(edge =>
<Quote key={edge.node.id} quote={edge.node} />
)}
</div>
</div>
)
}
}