简体   繁体   English

在Chrome的控制台上打印漂亮吗?

[英]Pretty printing in Chrome's console?

Is there a way to override the pretty-print that Chrome's console uses for JavaScript objects? 有没有办法覆盖Chrome控制台用于JavaScript对象的漂亮字体? I'm thinking about how HTML elements show up like so: 我正在考虑如何HTML元素显示如下:

在此处输入图片说明

Instead of showing the standard {} , it shows the XML markup used to create that object. 它没有显示标准的{} ,而是显示了用于创建该对象的XML标记。 Can I achieve something similar with my own objects? 我可以用自己的对象达到类似的目的吗?

Clarification: I'm interested in printing objects in my own format, not in XML format. 澄清:我有兴趣以自己的格式而不是XML格式打印对象。 For example, I'd like an instance of Foo with value 3 to be logged as as Foo(3) 例如,我希望将值为3的Foo实例记录为Foo(3)

Use the DevTools APIs to print in whichever required available format you need. 使用DevTools API以所需的任何所需可用格式进行打印。

console.dirxml(object);

I think console.log internally uses this api if the parameter passed is a DOM object. 如果传递的参数是DOM对象,我认为console.log在内部使用此api。

The above method prints the object in XML format and there are many other APIs like printing in directory format console.dir(object) and many others. 上面的方法以XML格式打印对象,还有许多其他API,例如以目录格式console.dir(object)打印等。 But you cannot create your own template, you must use the console.APIs provided by Dev-Tools. 但是您不能创建自己的模板,必须使用Dev-Tools提供的console.API。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM