Reputation: 1359
Is there a way to override the pretty-print that Chrome's console uses for JavaScript objects? I'm thinking about how HTML elements show up like so:
Instead of showing the standard {}
, it shows the XML markup used to create that object. Can I achieve something similar with my own objects?
Clarification: I'm interested in printing objects in my own format, not in XML format. For example, I'd like an instance of Foo with value 3 to be logged as as Foo(3)
Upvotes: 2
Views: 3054
Reputation: 6404
Use the DevTools APIs to print in whichever required available format you need.
console.dirxml(object);
I think console.log internally uses this api if the parameter passed is a DOM object.
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. But you cannot create your own template, you must use the console.APIs provided by Dev-Tools.
Upvotes: 3