How to Inherit the Classes in JavaScript?

By Prof. Fazal Rehman Shamil

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



Create Class    Animal

Create parameterized constructor pass parameter (name)

Give value speed = 0; = name

run (speed) //create method

this. speed += speed;// increase value of speed with 1

print}   runs with speed  this.speed

create a new method speed()

this.speed = 0;

print   stopped

class Rabbit extends Animal

hide() {

PRINT  hides

Create OBJECT rabbit = new Rabbit  White Rabbit   5.

Rabbit. Hide(); // White Rabbit hides!

Program of Classes Inheritance in JavaScript


parent to child relationship inheritance in Javascript

Topic Covered

Inheritance of the Classes in JavaScript.

Prof.Fazal Rehman Shamil (Available for Professional Discussions)
1. Message on Facebook page for discussions,
2. Video lectures on Youtube
3. Email is only for Advertisement/business enquiries.