chrome的console里颜色的含义是什么

console
如上图中,函数是浅紫色的代表什么?深紫色的是array中的值?

阅读 4k
2 个回答

个人经验推断
深紫色 是 键名
浅紫色 是 属性名
蓝紫色 是 数值

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.

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题