Is there a problem ?!

Hello… :wave:t4: :

In the following paragraph, is there a problem if I replace a :

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

with :

Teacher.prototype = Person.prototype;

https://developer.mozilla.org/en-US/docs/Learn/JavaScript/Objects/Inheritance#:~:text=Add%20the%20following%20line,available%20on%20Person.prototype.

Also, Can I have a simple explanation of what this method does :point_down::

Object.defineProperty(Teacher.prototype, 'constructor', {
    value: Teacher,
    enumerable: false, // so that it does not appear in 'for in' loop
    writable: true });

And Thanks in advance

Hi @albaraa_1949

Yes. See this response I gave recently: Inheritance in JavaScript

I’m trying to keep it simple :grin:
This is similar to what we would usually do to create a property on a object:

Teacher.prototype.constructor = Teacher;

With the defineProperty() we are able to change some special attributes. For example the call in your post will make sure that the property can’t be deleted and won’t appear when looping through all properties of the object.

I hope that was more or less clear and short enough :slightly_smiling_face:

Happy coding,
Michael

1 Like

Thank you very much, it’s simple :blush:

1 Like