Skip to content

Error to correct for Object.create #596

Closed Answered by AnilSeervi
Pierre-Thibault asked this question in Content
Discussion options

You must be logged in to vote

At first, we have an Object Literal named person,

const person = {
  isHuman: false,
  printIntroduction: function() {
    console.log(`My name is ${this.name}. Am I human? ${this.isHuman}`);
  }
};

On line: 8, in the demo example, a new object is created from the existing person object using the Object.create() method.

const me = Object.create(person);

Note that this creates a new object and doesn't just reference the person object.

On line: 10, you see a new property is being set on the me object, but not on person

me.name = 'Matthew'; // "name" is a property set on "me", but not on "person"

The same goes with overwriting the already defined properties, On line: 11

me.isHuman = true; /…

Replies: 2 comments 5 replies

Comment options

You must be logged in to vote
5 replies
@Pierre-Thibault
Comment options

@AnilSeervi
Comment options

@Pierre-Thibault
Comment options

@AnilSeervi
Comment options

@Pierre-Thibault
Comment options

Answer selected by pepelsbey
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
3 participants