为什么在自己搭建react项目或者在chrome里,在class中使用箭头函数来定义方法会报错
在看react的this绑定的时候看到了一个解决方法:
class test{
handleChange = () => {
// call this function from render
// and this.whatever in here works fine.
};
}
这种写法可以不用在constructor中绑定this 这种方式我在自己搭建的react和浏览器直接运行时都会报错这是为什么呢
6 回复
因为这语法不是合法的 class 语法.
class test{
handleChange() {
// call this function from render
// and this.whatever in here works fine.
};
}