如上图中,函数是浅紫色的代表什么?深紫色的是array中的值?
In JavaScript, properties may be enumerable or not. Non-enumerable properties are ignored by a for-in loop or Object.keys(). All built-in methods are non-enumerable. (This is why for-in does not list all of the methods on Object.prototype for every object.)
It appears that Chrome uses the dark purple to indicate an enumerable property and light purple to indicate non-enumerable. They do not need to be inherited. Demo (screenshot from Chrome 73.0.3683.103):
Object.defineProperties({}, {
foo: {enumerable: true, value: 1},
bar: {enumerable: false, value: 2},
});
If you want to get the properties of an object including even unenumerable ones, you can use Object.getOwnPropertyNames(o). However, you will need to follow the prototype chain yourself if you want to find inherited properties.
10 回答11.1k 阅读
6 回答3k 阅读
5 回答4.8k 阅读✓ 已解决
4 回答3.1k 阅读✓ 已解决
2 回答2.6k 阅读✓ 已解决
3 回答2.3k 阅读✓ 已解决
3 回答2.1k 阅读✓ 已解决
个人经验推断
深紫色
是 键名浅紫色
是 属性名蓝紫色
是 数值