6
I just asked that question How to clone an object in javascript?
And another question came to me. When I create an object from another with Object.create
the attribute is added to the new object __proto__
containing the content the object passed by argument of create
.
Thus:
function writeObject(obj)
{
document.write(JSON.stringify(obj));
}
a = {nome: 'wallace'}
b = Object.create(a);
writeObject(a);
writeObject(b);
writeObject(b.__proto__);
What does that mean __proto__
?
is an Function getter that is only created when an inheritance is made? vi in the documentation that should use Object.getPrototypeOf instead of
___proto___
in case it is clear to access the values...– Gabriel Rodrigues
I don’t know how it is implemented by engines, but it behaves like getter and Setter. In ES5 you can use
Object.getPrototypeOf
for the getter function, but for Setter has no alternative.– bfavaretto
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/setPrototypeOf but clear only on ES6
– Gabriel Rodrigues
Cool, I wasn’t sure if that method was past the Drafts for the final version, I’m glad.
– bfavaretto
In the MDN also says that the property
__proto__
is standardized from ES6.0 to ES7.– Klaider
@Matheus I updated the reply, thank you
– bfavaretto