Chrome 开发者控制台打印出变量的值 console.log(variable)
根据变量的类型使用不同的颜色。例如,string
值为黑色,null
值为灰色。
是否有任何文档是如何定义这些的?
是否可以为不同的值类型修改自定义颜色?比如基本的控制台消息:
console.log("%cBlue!", "color: blue;")
类型的默认颜色是固定的:
- 字符串值为黑色
- null/undefined 为灰色
- 数值为蓝色
- bool 值是蓝色
- 对象/数组值是黑色的(前面有箭头)
- 对象/数组属性为紫色
- 对象/数组属性字符串值为红色(引号)
您可以使用格式化程序修改某些类型(字符串、整数、 float )的输出,但您必须事先知道类型:https://developer.chrome.com/devtools/docs/console-api#consolelogobject-object
It seems that currently its not possible to have custom colors for types with automatic type detection.
最佳答案
Are there any documentation how these are defined?
是的。可以查看devtools提供的所有console api here .
Is it possible to modify custom colors for different value types?
没有。您只能使用 api。 API 不是通用的,无法添加您自己的颜色或格式。基于日志的类型或使用适当的 api 的任何内容。如 console.log
或 console.dirxml
等检查链接以获取更多 api。
关于javascript - Chrome Developer Console 中不同颜色的变量类型是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33476637/