It is very useful to be able to specify the debugging representation
of an object distinctively from it's toJSON or toString representation.
We've been using that to great effect in Prototype, to help out, for
example, with the debugging representation of DOM Elements:
<div id="foo" class="foo bar">
is a much more useful representation than:
[object HTMLDivElement]
which you get in Safari/Firefox/Chrome or worse:
[object Object]
which you get in IE.
Indeed, Object.prototype.toSource seems closer to what I was
interested in. Unfortunately, it's
1) non standardized, and
2) apparently used internally by FF[1].
To be useful for debugging, such a method needs to provide a good
default value and be easily overridden for custom objects. I wouldn't
be too keen on overriding a method which the browser vendor claims to
use internally.
Best,
Tobie
[1]
https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Object/toSource
On Mar 11, 2009, at 00:01 , Jason Orendorff wrote:
On Sat, Mar 7, 2009 at 9:18 PM, Tobie Langel
<[email protected]> wrote:
The lack of a more developer-friendly representation of objects
than the one
obtained through their toString method (or by calling
Object.prototype.toString) made me long for an ES equivalent of
Ruby's
inspect instance method.
You could use JSON.stringify(obj), which is on track to be
standardized in ES3.1.
(SpiderMonkey has the nonstandard uneval, as well as
Object.prototype.toSource, which I think are a bit closer to what you
want.)
-j
_______________________________________________
Es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss