Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue with "Inheritance and the prototype chain": "delete Operator with Object.create and new operator" is mixing up prototypal inheritance and direct assignment #2577

Closed
shuhei opened this issue Feb 22, 2021 · 1 comment
Labels
Content:JS JavaScript docs

Comments

@shuhei
Copy link

shuhei commented Feb 22, 2021

MDN URL: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Inheritance_and_the_prototype_chain

What information was incorrect, unhelpful, or incomplete?

The section "delete Operator with Object.create and new operator" shows different behaviors of delete with Object.create() and new. However, the difference is coming from the fact that the new example is directly setting a property (this.vertices = [4, 4];) in the constructor instead of using prototypal inheritance. It can give an impression that prototypal inheritance behaves differently depending on how to set it up (Object.create() vs new).

Specific section or headline?

"delete Operator with Object.create and new operator"

What did you expect to see?

It would be great to add an example of prototypal inheritance with new and show that its behavior with delete is the same as Object.create().

Did you test this? If so, how?

function Graph() {
  this.vertices = [4,4];
}
Graph.prototype.a = 123;

var g = new Graph();
console.log(g.a); // print 123
g.a = 234;
console.log(g.a); // print 234
delete g.a;
console.log(g.a); // print 123
MDN Content page report details
@shuhei shuhei changed the title Issue with "Inheritance and the prototype chain": "delete Operator with Object.create and new operator" is mixing up prototype inheritance and direct assignment Issue with "Inheritance and the prototype chain": "delete Operator with Object.create and new operator" is mixing up prototypal inheritance and direct assignment Feb 22, 2021
@Ryuno-Ki Ryuno-Ki added the Content:JS JavaScript docs label Feb 22, 2021
@shuhei
Copy link
Author

shuhei commented Aug 7, 2021

This was fixed by #3261.

@shuhei shuhei closed this as completed Aug 7, 2021
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 7, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Content:JS JavaScript docs
Projects
None yet
Development

No branches or pull requests

2 participants