我熟悉Javascript函數綁定。但我不明白爲什麼在以下React.js片段是這再次與這個。具有與構造共同的東西,因爲這在構造可根據使用情況有不同的價值觀?在構造函數中綁定(this)在ReactJS中做什麼
預先感謝您的答覆
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>
)
}
}