Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
428 views
in Technique[技术] by (71.8m points)

javascript - What is the significance of faded properties when using console.dir in Chrome Developer Tools Console

What does it mean when an object's property is slightly faded when using console.dir() in chrome's console.

For example, take a look at "top,width,worldVisible,x & y" in this screenshot.

Screenshot of developer tools

I've looked at the API reference here https://developer.chrome.com/devtools/docs/console-api#consoledirobject, but had no luck.

Thanks

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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);

then we see that hello is faded, while world is not.

console image showing faded <code>hello</code> property

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.

You can also check this with Object.getOwnPropertyDescriptor(obj, "worldVisible"), which should return an object with an enumerable: false property.

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...