Hi ! ,
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
Hi ! ,
can you tell me why you wrote like this :
Hello @Mohamed_Iyed and welcome to the community
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
Have a nice day,
Michael
that actually helped me a lot … thank you very much !