我的印象是箭头功能和类都是ES6的功能。那么为什么这些箭头功能在类中不起作用?谁能解释这里的问题?为什么以下方法不起作用?
class Car {
constructor(brand) {
this.setBrand(brand);
}
/*setBrand(brand) {
this.brand = brand;
}*/
/*getBrand() {
return this.brand;
}*/
setBrand = brand => this.brand = brand;
getBrand = () => this.brand;
getAd = () => `${this.brand} is the best brand out there!!`;
}
mycar = new Car("Ford");
console.log( mycar.getAd() );
我收到以下错误消息。
setBrand = brand => this.brand = brand;
^
SyntaxError: Unexpected token =
at Module._compile (internal/modules/cjs/loader.js:723:23)