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