Start networking and exchanging professional insights

Register now or log in to join your professional community.

Follow

Can you explain how inheritance works in JavaScript?

user-image
Question added by Rizwan Shah , Project Manager , COMSATS IIT
Date Posted: 2014/09/30
Ibrahim Ahmed
by Ibrahim Ahmed , CEO/CTO/Fullstack Developer , Stack Bytes

Look here's a simple example of how you can benefit from inheritance in JS

 

var Person = function(name){ 

    this.name = name;

};

 

var Student = undefined;

 

var Student = function(id, name){ 

    this.id = id;

    Person.call(this, name);

};

 

Student.prototype = Object.create(Person.prototype);

 

Student.prototype.constructor = Student;

 

var St1 = new Student('59gh14oq6', 'Inigo Montoya');

More Questions Like This

Do you need help in adding the right keywords to your CV? Let our CV writing experts help you.