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

Content suggestion: Mention __proto__ in object literal initializers in the "Inheritance and the prototype chain" tutorial #16068

Closed
Josh-Cena opened this issue May 15, 2022 · 1 comment · Fixed by #16090
Assignees
Labels
Content:JS JavaScript docs

Comments

@Josh-Cena
Copy link
Member

Josh-Cena commented May 15, 2022

What is the new suggestion?

This pattern should be mentioned:

const obj = { __proto__: null, a: 1 };

In addition to the Object.create method.

Why is it important or useful?

It's important to note that while Object.prototype.__proto__ is deprecated and non-standard, the __proto__ in literal initializers is standard and probably not any less efficient than Object.create [citation needed]. It's important for MDN to highlight the difference between the two.

Slightly off-topic: the Object.prototype.__proto__ documentation mentioned that:

The __proto__ property can also be used in an object literal definition to set the object [[Prototype]] on creation.

Which can be confusing as well, because __proto__ in object literals is a special construct, not relevant to Object.prototype.__proto__.

I'm open to contributing the two fixes myself, mostly just want to see if anyone has sources on whether __proto__ in initializers are less/more efficient than Object.create.

Other supporting information

@github-actions github-actions bot added the needs triage Triage needed by staff and/or partners. Automatically applied when an issue is opened. label May 15, 2022
@sideshowbarker
Copy link
Collaborator

I'm open to contributing the two fixes myself, mostly just want to see if anyone has sources on whether __proto__ in initializers are less/more efficient than Object.create.

Thanks — I’ve assigned this to you, so please do go ahead and open a PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Content:JS JavaScript docs
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants