class myCat extends myAnimal {
myShow(){
document.getElementById('myDiv01').innerHTML = this.myName
}
}
The "extends" keyword inherits all methods from another class.
The "super" method calls the parent's constructor function.
The "extends" keyword inherits all methods from another class.
The "super" method calls the parent's constructor function.
<p id="ytj"></p>
<script>
class Car {
constructor(brand) {
this.carname = brand;
}
present() {
return 'My favourite food is ' + this.carname;
}
}
class Model extends Car {
constructor(brand, mod) {
super(brand);
this.model = mod;
}
show() {
return this.present() + ', it is ' + this.model;
}
}
mycar = new Model("Indian", "Chicken Curry");
document.getElementById("ytj").innerHTML = mycar.show();
</script>
<p id="hj"></p>
<script>
class Car {
constructor(brand) {
this.carname = brand;
}
static hello() {
return "Hello!, this text is written using static class.";
}
}
mycar = new Car("Ford");
document.getElementById("hj").innerHTML = Car.hello();
</script>