无法将箭头函数存储在React组件的let/var中

问题描述:

我有一个组件由扩展 React.Component 定义.其中的内部以及render方法是:

I have a component in react defined by extends React.Component. Inside it, along with the render method, is:

constructor(props, context) {
    super(props, context);

    this.state = {
        open: false,
    };
}

handleClose = () => { //this works
    this.setState({open: false});
};

handleOpen = () => { //this works
    this.setState({open: true});
};

let empty = () => {}; // does not work, error  Parsing error:      Unexpected token

如果我在let或const的任何箭头函数前面加上前缀,我似乎会遇到意外的令牌错误.我在这里想念什么吗?

I seem to get an unexpected token error if I prefix any of the arrow functions with let or const. Am I missing something here?

谢谢

阅读 babel文档关于课程.使用letconst并不是类定义的ES6可能前缀的一部分

Read babel documentation about classes. using let or const is not part of ES6 possible prefix for classes definition