Assigning Parent object's prototype vs Object.create(Parent.prototype)

Hi all,

I’ve been following the Learn Web Development track and this is my first time on the forums.

Understanding Object prototypes and inheritance has been a super confusing journey so far. In this article we’re supposed to set Teacher()'s prototype and set constructor reference. A few questions:

  1. Why is the below code necessary after we’ve defined a Teacher constructor function using in the function body?
Teacher.prototype = Object.create(Person.prototype);
  1. Why can’t we do this instead?
Teacher.prototype = Person.prototype;

Apologies if this is a noob question, I just haven’t been able to wrap my head around this.

Hello @lakshverma23

do not be sorry and i also see that the coding style is confusing in js

so let me ask @chrisdavidmills to help you with that

and have a nice day both of you :slight_smile:

1 Like

Thanks @justsomeone! Would love to hear from @chrisdavidmills :slight_smile:

you very welcome :slight_smile:

Pushing this back up. Could anyone please help me understand this?

Hey @Ran @ayanda could you help us here

Will have a look tonight @Justsomeone.

thanks a lot @Ran :slight_smile:


Apologies, just a bit busy these days. I think @lakshverma23 question is a great one. I am still looking into it. The way I work is to run the code itself and see the outcome.

So when we use

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

The outcome when I run


on the console is

when I run the it with the following

Teacher.prototype = Person.prototype;

the outcome when I run


is the following

You might notice the double forware slashes on the last image where it starts with “// Teacher.prototype = …”

so I am just wondering if there is any object inheritance in this case and if the prototype of teacher is person in this case. I m going to have to look a bit further and get back.

nice idea @Ran

think we need to call some of the methods defined in person using teacher object for both cases and see if both inhirit it or not

well done @Ran