You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
What specific section or headline is this issue about?
No response
What information was incorrect, unhelpful, or incomplete?
What did you expect to see?
this article say each object has an internal link to another object called its prototype.But other say Also allows the creation of objects without a prototype, using Object.create(null).I want know which is right.
Do you have any supporting links, references, or citations?
No response
Do you have anything more you want to share?
No response
The text was updated successfully, but these errors were encountered:
We should remove the mention of Object.create(null), as literally every other object creation method allows null prototypes here. I also think "without a prototype" is technically wrong but I think few people go into that level of detail as "null prototype" and "no prototype" are generally the same thing.
Josh-Cena
added
good first issue
A good issue for newcomers to get started with.
and removed
needs triage
Triage needed by staff and/or partners. Automatically applied when an issue is opened.
labels
May 11, 2024
@pengzhijian In js, yes every object has a internal [[Prototype]] "link" which points to some 'prototype object'.
For new objects created in manner, let obj = {};, the default 'prototype object' is Object.prototype, i.e. these new objects can not have their [[Prototype]] link be pointed to `null' (often said as "to not have a prototype").
So to create objects with null as their [[Prototype]], we do,
letobj={};Object.getPrototypeOf(obj)==Object.prototype// trueobj.__proto__=null// now the [[Prototype]] is nullObject.getPrototypeOf(obj)==Object.prototype// false
With Object.create(null) what took two lines, now takes one line.
In both cases, the [[Prototype]] is pointing to an 'prototype object', it's just in obj = {} that 'prototype object' has some pre-existing key-value pairs (Object.prototype). In contrast to Object.create(null), whose 'prototype object' has no key-value pairs.
In the screenshot, I agree, "without a prototype" can be confusing if taken too literally.
Other than that, on technicality the screenshot is correct.
MDN URL
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Inheritance_and_the_prototype_chain
What specific section or headline is this issue about?
No response
What information was incorrect, unhelpful, or incomplete?
What did you expect to see?
this article say each object has an internal link to another object called its prototype.But other say Also allows the creation of objects without a prototype, using Object.create(null).I want know which is right.
Do you have any supporting links, references, or citations?
No response
Do you have anything more you want to share?
No response
The text was updated successfully, but these errors were encountered: