Answers for "es6 class and functions"

8

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
Posted by: Guest on May-31-2020
0

javascript es6 class

class MyClass {
  constructor() {
    this.answer = 42;
  }
}

const obj = new MyClass();
obj.answer; // 42
Posted by: Guest on February-19-2021

Code answers related to "Javascript"

Browse Popular Code Answers by Language