Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Chrome devtools console: see toString representation of an object?

After having Firefox (FireBug) crash for the 30th time during debugging (I'm on Ubuntu), I decided to use Chrome. For the most part, it's great. I've just one big issue. In FireBug when you logged something to the console you always get the string representation of the object. As a result it made good sense to implement toString on most of your prototypes allowing for the most important information to be displayed anytime an object appeared anywhere in the developer panels or console.

If my code logs the following:

console.log(bill_gates);

I don't want the first representation of my object in the console to be:

Object

when it could be:

Person{Bill Gates, Microsoft Founder, dob: Oct 28}

And I shouldn't have to double log everything to compensate for this shortcoming:

console.log(bill_gates, bill_gates.toString());

Besides double-logging doesn't help when you drill down into an object and find that your object is composed of other objects that are all labelled "Object".

Imagine going to a party where everyone's name badge says "Person". What I want is a little more detail about that person's identity, perhaps "Ned Campbell, Realtor" or "Sue Bradshaw, Insurance Sales". In FireBug, your objects wear custom name badges (based on your toString implementation). In Chrome, all your objects wear name badges that say "Object". You have to spend time interrogating the object (drilling down into its properties and methods) to figure out what object you're dealing with. What a waste.

This to me is a MAJOR oversight in the design of the otherwise superb Chrome Devtools. Is there some way (an extension maybe) to make the Devtools show string representations of objects (wherever they appear) as FireBug does?

like image 516
Mario Avatar asked Feb 04 '12 17:02

Mario


1 Answers

Regarding the second part of your question: yes, there is a bug filed against Web Inspector (in the WebKit bugzilla.) Feel free to CC yourself on it (once you have registered there.)

like image 72
Alexander Pavlov Avatar answered Nov 15 '22 06:11

Alexander Pavlov