Re: [Bindings] stringify

On 24/12/2007, Anne van Kesteren <annevk@opera.com> wrote:
> Maybe the draft already says something about this, but I couldn't find it.
> I think it would be good if there was a way in the IDL to say what an
> object stringifies to. The Window object becomes "[object Window]" and
> Location stringifies to its href attribute value. The tricky part here is
> objects implementing multiple interfaces, such as Document and
> DocumentSelector, but in those cases the specification editors should
> probably ensure there are no strange things.

I've been meaning to address this (or a related issue, anyway) in a
mail to both ES4-discuss and to WebAPI.
Wouldn't it be best to specify which interface is the main interface
for objects? ECMAScript assumes a strict single inheritance scheme.

> Jim Ley wrote:
> > Could you describe the use cases for defining this at all?

On 24/12/2007, Boris Zbarsky <bzbarsky@mit.edu> wrote:
> Interoperability.  Specifying that Window stringifies to [object Window]
> is probably unnecessary (and not true in all UAs anyway).  But
> specifying that, Location stringifies to its .href property is needed
> (and is interoperably implemented).

Well, the ECMAScript spec already specifies how objects stringify. If
the [[Class]] internal attribute of the implementing object contains
the value "Window", then the correct stringification would be "[object
Window]". Which is probably the best solution for Window. Location
probably needs to override toString.
-- 
David "liorean" Andersson

Received on Tuesday, 25 December 2007 10:19:35 UTC