How to Inherit the Classes in JavaScript?

By: Prof. Dr. Fazal Rehman | Last updated: March 3, 2022

How to Inherit the Classes in JavaScript?

Inheritance in JavaScript describes the notion that one object’s methods/properties are available to be used via another object. … But with the delegation, those changes are then available, which has a term in the inheritance world: retroactive inheritance.
How to Inherit the Classes in JavaScript
Figure: How to Inherit the Classes in JavaScript

Algorithm of Classes Inheritance in JavaScript

  1. Open Notepad/notepad++/Dreamweaver
  2. Create new
  3. First include <html> tag ,<body> tag
  4. Declare a class with the name of Animal with class keyword
  5. Create constructor with constructor keyword and pass parameters of name
  6. Assign values in name and speed variables through constructor
  7. Create a method for speed with the name of Run and pass speed as a perimeter
  8. Increase the value of speed initially by 1.
  9. Print the value of speed with an animal name
  10. Create new class rabbit with keyword Class
  11. Inherit this class with parent class Animal by using the keyword extends
  12. Create a new method with the name of hiding for giving value in the name.
  13. Create an object of rabbit class with the name of Rabbit
  14. At the time of the creation of an object called the parameterized constructor to give value in the name “white”.
  15. Call the method of Run and Hide with this object.

Pseudocode of Classes Inheritance in JavaScript

<Html> <Body> Create Class    Animal Create parameterized constructor pass parameter (name) Give value speed = 0; this.name = name run (speed) //create method this. speed += speed;// increase value of speed with 1 print  this.name}   runs with speed  this.speed create a new method speed() this.speed = 0; print this.name   stopped class Rabbit extends Animal hide() { PRINT this.name  hides Create OBJECT rabbit = new Rabbit  White Rabbit   rabbit.run   5. Rabbit. Hide(); // White Rabbit hides!

Program of Classes Inheritance in JavaScript

Output parent to child relationship inheritance in Javascript Topic Covered Inheritance of the Classes in JavaScript.

Leave a Comment

All Copyrights Reserved 2025 Reserved by T4Tutorials