javascript inheritance es6 code example

Example 1: node js inheritance es6

class Vehicle {   constructor (name, type) {    this.name = name;    this.type = type;  }   getName () {    return this.name;  }   getType () {    return this.type;  } }class Car extends Vehicle {   constructor (name) {    super(name, 'car');  }   getName () {    return 'It is a car: ' + super.getName();  } }let car = new Car('Tesla');console.log(car.getName()); // It is a car: Teslaconsole.log(car.getType()); // car

Example 2: javascript inheritance

function Teacher(first, last, age, gender, interests, subject) {
  Person.call(this, first, last, age, gender, interests);

  this.subject = subject;
}