By calling the super() method in the constructor method, we call the parent's constructor method and gets access to the parent's properties and methods:
class Car {
constructor(brand) {
this.carname = brand;
}
present() {
return 'I have a ' + this.carname;
}
}
class Model extends Car {
constructor(brand, mod) {
super(brand);
this.model = mod;
}
show() {
return this.present() + ', it is a ' + this.model;
}
}
mycar = new Model("Ford", "Mustang");
document.getElementById("demo").innerHTML = mycar.show();
class Animal{
constructor()
{
this.walk = "walk";
}
}
class Dog extends Animal{
constructor()
{
super();
this.bark = "bark";
}
}
const dog = new Dog();
console.log(dog.walk);
/*must include BOTH extends and super()*/