I was under the impression that both arrow functions and classes were a feature of ES6. Then why do these arrow functions not work within the class? Would anyone be able to explain what the problem is here? Why doesn't the following work?
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() );
I get the following error.
setBrand = brand => this.brand = brand;
^
SyntaxError: Unexpected token =
at Module._compile (internal/modules/cjs/loader.js:723:23)