Reputation: 2599
When I do console.log(someobject)
, I see some __proto__
object things inside my object, which contain a huge amount of data in them.
If I have a lot properties on my objects (properties that are also objects), I can easily get hundreds of protos. Anyway does this affect performance in any way? Should I use arrays instead?
Upvotes: 0
Views: 492
Reputation: 5857
This may slow down the console.log
calls, but not not your application in production mode.
Anyway the __proto__ property of Object
objects is a non-standard and deprecated Mozilla extension, it is going to be removed someday so don't worry about it (the standard Object.getPrototypeOf(obj)
method can already bu used instead of obj.__proto__
).
Upvotes: 1
Reputation: 74086
Familiarize yourself with the prototypical inheritance JavaScript uses. See, e.g., here at MDN.
In a nutshell: Objects in JavaScript are not created by instantiating classes, but creating an object that is like another object (the prototype). So every object has a pointer to its prototype.
If a method or attribute of an object is required at some point in the code, the compiler checks, whether the object posseses such a property itself (comp. hasOwnProperty()). If not, it takes a look at the respective prototype object. If the property can not be found there it looks at the prototype of the prototype an so forth. This is done all the way up to Object
, which is the base prototype in JavaScript. The chain of prototypes is also called prototype chain
.
As this is an inherent feature of the language you can not circumvent it anyways and thus it wont have any impact on your specific site's performance.
Upvotes: 1
Reputation: 916
It's just part of JavaScript's internal prototype chain. Whenever a new object is created, its __proto__
property is set to its "parent" object's prototype
property. To answer your question, it has no impact on performance that you can control directly, so don't worry about it.
If you want to read more about it, check out MDN, https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Object/Proto
Upvotes: 1