WebMasterCampus
WEB DEVELOPER Resources

Javascript ES6 Classes

Learn Javascript ES6 Classes


Javascript classes

Javascript classes are template for Javasript objects. We can use class keyword to create class. In addition always use a method name constructor() inside the class.

Javascript classes Example


class Rectangle {
  constructor(height, width) {
    this.height = height;
    this.width = width;
  }

  get area() {
    return this.calcArea();
  }

  calcArea() {
    return this.height * this.width;
  }


}


var r = new Rectangle(6,6);

console.log( r.calcArea() );
Created with love and passion.