class LoggingButton extends React.Component {
handleClick = () => {
console.log('this is:', this)
}
render() {
return (
<button onClick={this.handleClick}>
Click me
</button>
)
}
}
class LoggingButton extends React.Component {
constructor () {
super(props)
this.handleClick = this.handleClick.bind(this)
}
handleClick () {
console.log('this is:', this)
}
render() {
return (
<button onClick={this.handleClick}>
Click me
</button>
)
}
} 箭头函数式
非箭头函数式
运行效率相同
无法确定