On Mar 11, 2009, at 4:20 AM, Tobie Langel wrote:
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]
True, although you have to ampersand-escape it if it flows into markup.
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.
What text in the link you give made you think anything of the sort? I
see no use of "internally" or "internal" in that wiki page. You can
override toSource just as you can override toString. Doing so in a
content window cannot possibly affect the operation of the browser's
user interface ("chrome") windows.
/be
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
_______________________________________________
Es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss