3

As answers in this question suggest, you could override toString() method on objects to provide useful information during debugging (at least). This works nicely in Firebug, but this doesn't help at all in Chrome:

x = { toString: function () { return 'test' } }

gives a very helpful output:

Object

while in Firebug it's much better:

test { toString=function()}

I know that Chrome allows me to inspect object properties. This is useful, but it is much easier to have the object title list at least a few most important ones, so that you don't have to dig through 50 properties of a complex object just to find out one value.

So, is it somehow possible to make debug output in Chrome more useful?

EDIT:

This is what I want to achieve:

v  [result of ???() on x]
    a: 1
    b: 'foo'
  v c: [result of ???() on x.c]
      foo: 'bla bla bla'
    > bar: [result of ???() on x.c.bar]
Community
  • 1
  • 1
  • 1
    Why don't you use console.log() – The Alpha Mar 18 '12 at 12:56
  • 2
    @SheikhHeera: And how would this help with my problem? –  Mar 18 '12 at 12:58
  • @doublep: Why don't you call it exclusively? `console.log(x.toString())`, and if you wish to add expansible version, add `console.log(x)` immediately after it. Will that help? – Tadeck Mar 18 '12 at 13:04
  • @Tadeck: Not much. In this usecase `toString()` plays no role at all and when I inspect properties of `x`, they are not printed out nicely, again as useless `Object`. –  Mar 18 '12 at 13:09
  • @doublep: Could you explain it further? You are trying to display `x.toString()` result along with object representation, but you also say `toString()` plays no role for you. Is it the representation of properties of the main object that concerns you? – Tadeck Mar 18 '12 at 13:17
  • @Tadeck: It plays no special role *here*. Yes, I know I can call a method manually. –  Mar 18 '12 at 13:21

1 Answers1

-2

You can use it like that:

console.log(x.toString(), x)

It will give you the result of x.toString() and expansible representation of x in the same line.

Tadeck
  • 132,510
  • 28
  • 152
  • 198
  • 3
    And when I expand the `x` printed as `Object` I get useless `Object` for its properties, regardless of whether the property values implement `toString()` or not. This is *not* useful. You basically told me how I can manually call a method. –  Mar 18 '12 at 13:19