What is the need for __proto__?

Asked

Viewed 810 times

2

What is the need for "__proto__" on an object? I just did some tests and realized that "__proto__" is not a property, but can be indexed.

When I define a property in x object, this property is also available in "__proto__", but when I do the vice versa the property is not available in x object.

"__proto__" seems similar to Object because it has some properties with the same name

obj#__proto__

The global object seems to have "__proto__" differently

window#__proto__

If so, what "__proto__" makes it so special in Javascript? The differences between #__proto__ and Function#prototype make sense, but #__proto__ in itself makes no sense.

1 answer

2


__proto__ contains a reference to the internal prototype of the specified object. It can be used to define the prototype for an object.

The object or function inherits all new prototype methods and properties along with all methods and properties in the prototype chain of the new prototype. An object may have only a single prototype (not including prototypes inherited in the prototype chain), so that when you call the property __proto__, you replace the previous prototype.

I found this image interesting, I removed from this reply stackoverflow.

inserir a descrição da imagem aqui

There are already answers explaining theory that may be useful:

Browser other questions tagged

You are not signed in. Login or sign up in order to post.