According to the information provided by mdn in their documentation on JavaScript's Inheritance and the prototype chain, it is stated
All objects inherit the
Object.prototype.__proto__
setter, which can be used to set the [[Prototype]] of an existing object (if the__proto__
key is not overridden on the object).
However, they also mention that
Object.prototype.__proto__
accessors are non-standard and deprecated. It is recommended to use Object.setPrototypeOf instead.
They provide an example as well:
const obj = {};
// THIS IS NOT ADVISED: for demonstration purposes only.
obj.__proto__ = { barProp: 'bar val' };
obj.__proto__.__proto__ = { fooProp: 'foo val' };
console.log(obj.fooProp);
console.log(obj.barProp);
The confusing part comes when they introduce this initial example:
const o = {
a: 1,
b: 2,
// __proto__ sets the [[Prototype]]. It's specified here
// as another object literal.
__proto__: {
b: 3,
c: 4,
},
};
By stating,
The syntax
{ __proto__: ... }
is distinct from theobj.__proto__
accessor: the former being standard and not deprecated.
What sets apart { __proto__: ...}
from obj.__proto__
? As both are object properties, it is unclear what exactly distinguishes them in this context.