简体   繁体   English

Console.log显示隐藏的对象信息

[英]Console.log shows hidden object info

When I do console.log(someobject) , I see some __proto__ object things inside my object, which contain a huge amount of data in them. 当我执行console.log(someobject) ,我在对象内部看到了一些__proto__对象,其中包含大量数据。

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? 我应该改用数组吗?

It's just part of JavaScript's internal prototype chain. 它只是JavaScript内部原型链的一部分。 Whenever a new object is created, its __proto__ property is set to its "parent" object's prototype property. 每当创建新对象时,其__proto__属性都设置为其“父”对象的prototype属性。 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 如果您想了解更多信息,请查看MDN, https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Object/Proto

Familiarize yourself with the prototypical inheritance JavaScript uses. 熟悉JavaScript使用的原型继承。 See, eg, here at MDN . 参见,例如, 此处在MDN

In a nutshell: Objects in JavaScript are not created by instantiating classes, but creating an object that is like another object (the prototype). 简而言之:JavaScript中的对象不是通过实例化类来创建的,而是通过创建类似于另一个对象(原型)的对象来创建的。 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() ). 如果在代码中的某个位置需要对象的方法或属性,则编译器将检查对象本身是否具有这样的属性(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. 一直到Object为止,这都是JavaScript的基本原型。 The chain of prototypes is also called prototype chain . prototype chain也称为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. 由于这是该语言的固有功能,因此您无论如何都不能规避它,因此不会对您特定站点的性能产生任何影响。

This may slow down the console.log calls, but not not your application in production mode. 这可能会降低console.log调用的速度,但不会降低生产模式下的应用程序的速度。 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__ ). 无论如何, Object对象的__proto__属性是一个非标准且已弃用的Mozilla扩展,它将有一天被删除,因此不必担心(标准的Object.getPrototypeOf(obj)方法已经可以代替obj.__proto__ )。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM