问题描述
在chrome控制台中使用console.dir()时,当对象的属性稍微褪色时,这意味着什么。
What does it mean when an object's property is slightly faded when using console.dir() in chrome's console.
例如,看看 width,worldVisible,x& y。
For example, take a look at "top,width,worldVisible,x & y" in this screenshot.
我在这里查看了API参考资料,但没有运气。
I've looked at the API reference here https://developer.chrome.com/devtools/docs/console-api#consoledirobject, but had no luck.
谢谢
推荐答案
淡化的属性apper表示不可枚举的属性。如果我们这样做:
Faded properties apper to indicate non-enumerable properties. If we do:
var a = {};
Object.defineProperties(a, {
hello: { enumerable: false },
world: { enumerable: true }
});
console.dir(a);
然后我们看到 hello
而 world
不是。
在您的代码中,如果您执行 for(prop in obj){console.log(prop); }
(其中 obj
是您在控制台屏幕截图中显示的任何对象),您将看到只有褪色的属性未枚举
In your code, if you do for(prop in obj) { console.log(prop); }
(where obj
is whatever object you're showing us in your console screenshot), you'll see that only the faded properties are not enumerated.
您还可以使用 Object.getOwnPropertyDescriptor(obj,worldVisible)
对象与枚举:false
属性。
You can also check this with Object.getOwnPropertyDescriptor(obj, "worldVisible")
, which should return an object with an enumerable: false
property.
请注意,该属性的斜体名称表示属性值由getter函数定义。 (这也导致该值在运行函数之前显示一个(...)
值。)这是一个与枚举性完全不同的问题,这导致名称为褪色您可以具有不是褪色的非可枚举属性的斜体getter定义的属性,反之亦然。
Note that the italics on the property names indicate that the property value is defined by a getter function. (This also causes the value to display a (...)
value before the function is run.) This is a totally separate issue from enumerability, which causes the names to be faded. You can have italic getter-defined properties that are not faded non-enumerable properties, and vice versa.
这篇关于在Chrome Developer Tools Console中使用console.dir时,褪色属性的意义是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!