Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

super class js

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();
Comment

super method with class in javascript

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()*/
Comment

PREVIOUS NEXT
Code Example
Javascript :: make an arry from a string 
Javascript :: clear timeout in function js 
Javascript :: how to return the max and min of an array in javascript 
Javascript :: using hooks with apis 
Javascript :: change object in array in state 
Javascript :: this.props undefined react native 
Javascript :: expo font 
Javascript :: javascript inbuilt funcctions to match the word and return boolean 
Javascript :: iterate loop over mapping in solidity 
Javascript :: how to get data-target value in jquery 
Javascript :: check the number is palindrome or not 
Javascript :: javascript get params from query string json object 
Javascript :: heroku buildpacks with react 
Javascript :: vue 3 apollo client 
Javascript :: celebrate node js 
Javascript :: js reverse a strings in array 
Javascript :: ruby on rails test if all parameters in json request are here 
Javascript :: submit form react js 
Javascript :: gltfjsx 
Javascript :: export module in es6 
Javascript :: toisodatestring 
Javascript :: How do i write a script which generates a random rgb color number. 
Javascript :: redux saga fetch data using axios 
Javascript :: htmlfor jsx attr 
Javascript :: array destructuring 
Javascript :: how to append object in array javascript 
Javascript :: js fetch status of 500 
Javascript :: in vs of javascript 
Javascript :: js start at this character 
Javascript :: quiz javascript example with array 
ADD CONTENT
Topic
Content
Source link
Name
2+9 =