Error to correct for Object.create #596
Unanswered
Pierre-Thibault
asked this question in
Content
Replies: 0 comments 6 replies
-
At first, we have an Object Literal named 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 const me = Object.create(person);
On line: 10, you see a new property is being set on the 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; // inherited properties can be overwritten And on line: 13, the me.printIntroduction();
// expected output: "My name is Matthew. Am I human? true" Hope this helps you understand what the example is trying to convey! |
Beta Was this translation helpful? Give feedback.
5 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I don't know how to edit the first code example at https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/create. It says: "// inherited properties can be overwritten" but there is no property overwritten on this line. It creates a new property at the object level. The property is still present in the prototype and can be access using
Object.getPrototypeOf(me).isHuman
. Maybe it should say that properties can be override and that the original property can still be accessed in the prototype.Beta Was this translation helpful? Give feedback.
All reactions