First I write the code below in development tool, and all work fine:
class MyClass {
constructor(name, verb, noun) {
this.name = name;
this.verb = verb;
this.noun = noun;
}
myFunc() {
return `${this.name}${this.verb}${this.noun}`
}
}
But, if I change it to:
class MyClass {
constructor(name, verb, noun) {
this.name = name;
this.verb = verb;
this.noun = noun;
}
myFunc = () => {
return `${this.name}${this.verb}${this.noun}`
}
}
just transferring traditional function to arrow function, it will tell me:
Uncaught SyntaxError: Unexpected token =
Can't I write arrow function in class?