题库 软件开发 题目列表 在 React 项目中,绑定 `this` 通常有如下两种写法:...
单选题
在 React 项目中,绑定 `this` 通常有如下两种写法:
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>
        )
    }
}
哪种写法运行效率更高?
A.

箭头函数式

B.

非箭头函数式

C.

运行效率相同

D.

无法确定

题目信息
校招真题
-
正确率
0
评论
18
点击