我下面的教程的Facebook和我有一个关于下面的代码问题:React ES6语法。它是立即传递函数还是调用函数?
handleClick(i) {
const squares = this.state.squares.slice();
if (calculateWinner(squares) || squares[i]) {
return;
}
squares[i] = this.state.xIsNext ? 'X' : 'O';
this.setState({
squares: squares,
xIsNext: !this.state.xIsNext
});
}
renderSquare(i) {
return <Square value={this.state.squares[i]} onClick={() => this.handleClick(i)} />;
}
某处存在Square
组件,但现在不担心了。我的问题是onClick
道具上发生了什么。什么是右边?它看起来像定义一个Javascript函数的ES6语法。但是我们是否将handleClick函数传递给它或调用它? ES5中减少了什么?
是不是this.handleClick(i)
立即调用函数,而不是传递它?
你读过[MDN约箭头函数的文档(https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference /功能/ Arrow_functions)? –