Inheritance in JavaScript

Hi ! ,:slightly_smiling_face:
can you tell me why you wrote like this :


not just : Teacher.prototype = Person.prototype
Article link : https://developer.mozilla.org/enUS/docs/Learn/JavaScript/Objects/Inheritance

Hello @Mohamed_Iyed and welcome to the community :wave:

From Object.create():

The Object.create() method creates a new object, using an existing object as the prototype of the newly created object.

With the assignment in your screenshot we achieve that Teacher.prototype has Person.prototype as its prototype. In other words: Teacher.prototype inherits from Person.prototype.
If we are just doing Teacher.prototype = Person.prototype, Teacher.prototype is the same as Person.prototype and we have no inheritance.

I hope that helps. Feel free to ask more questions if you like :slightly_smiling_face:

Have a nice day,
Michael

3 Likes

that actually helped me a lot … thank you very much !

2 Likes