what is class in ES6 code example
Example 1: classes in es6
class Rectangle {
constructor(height, width) {
this.height = height;
this.width = width;
}
// Getter
get area() {
return this.calcArea();
}
// Method
calcArea() {
return this.height * this.width;
}
}
const square = new Rectangle(10, 10);
console.log(square.area); // 100
Example 2: javascript es6 class
class MyClass {
constructor() {
this.answer = 42;
}
}
const obj = new MyClass();
obj.answer; // 42