Classes

class Test{
 doWork(){
  return "Class Test";
 }
 testMethod(){
  return "Method";
 }
}
 let t = new Test();  
 
 e.doWork();     //returns "Class Test"
 e.testMethod(); //returns "Method"

constructor

class Employee{

 constructor(name){
  this._name = name;
 }
 getName(){
  return this._name;
 }
}
 
let e1 = new Test("John");  
let e1 = new Test("Jane");  

 
e1.getName();     //returns "John"
e2.getName();     //returns "Jane"

getters and setters

Inheritance

used when there "is-a" relationship.

class Person{ contrustor(name){ this.name = name; } get name(){ return this._name; } set name(){ if(value) this._name = value; } } }

super keyword

super key is used to call/invoke the parent's constructor.

class Person{ contrustor(name){ this.name = name; } get name(){ return this._name; } set name(){ if(value) this._name = value; } } }

override methods

  • super keyword

  • toString

Last updated

Was this helpful?