Communiquez avec les autres et partagez vos connaissances professionnelles

Inscrivez-vous ou connectez-vous pour rejoindre votre communauté professionnelle.

Suivre

Can you explain how inheritance works in JavaScript?

user-image
Question ajoutée par Rizwan Shah , Project Manager , COMSATS IIT
Date de publication: 2014/09/30
Ibrahim Ahmed
par 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

Avez-vous besoin d'aide pour créer un CV ayant les mots-clés recherchés par les employeurs?