I am confused about one of the syntaxes in ES7. I define a class as:
class Employee2 {
Ename = "Rahul";
printName = () => {
console.log(this.Ename);
}
}
Since classes are syntactical sugar over existing prototype concept, I expected that the method 'printName' would actually go to function prototype. But that did not happen, the method is an object property.
However, if I do:
class Employee {
Ename = "Rahul";
printName () {
console.log(this.Ename);
}
}
this works as expected where printName goes to the prototype. Now my query:
ES7 suggests using the syntax as in first code Employee2 class, if I use that I miss the method definition on the prototype. Is there a way to achieve the method on function prototype?