---
atras
ES6 introduced a shorthand that does not require the keyword function for a function assigned to a method's name. One type of class method is the prototype method, which is available to objects of the class.
For Example:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
class Rectangle{
constructor(height, width) {
this.height = height;
this.width = width;
}
get area() {
return this.calcArea();
}
calcArea() {
return this.height * this.width;
}
}
const square = new Rectangle(5, 5);
console.log(square.area); // 25
note:in the code above,area is a getter,calcArea is a method