- From: Garrett Smith <dhtmlkitchen@gmail.com>
- Date: Sun, 30 Dec 2007 18:39:52 -0800
- To: "Web API WG (public)" <public-webapi@w3.org>
On Dec 30, 2007 5:49 PM, Cameron McCormack <cam@mcc.id.au> wrote: > > Anne van Kesteren: > > 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. > > Jim Ley: > > Could you describe the use cases for defining this at all? I can't see any > > benefits. > > Boris Zbarsky: > > 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). > > It would be interesting to know if there are scripts that rely on > extracting the [[Class]] of DOM objects from that output of > Object.prototype.toString. I've added a [Stringifies] extended > attribute to handle the Location case. > Checking an object's toString return value to try and determine what it is is not a reliable way to check what type of object it is: toString() says nothing about an object's interface, other than the fact that, if no error is thrown, it supports toString(). For example: "[object Window]".toString() Method toString is useful for providing a readable representation of an object's state. In ES, as David said, it's "[object " + [[Class]] + "]". Prototype's "inspect" provides the type of functionality that I advocate in a toString. They probably called their method "inspect" as a way of avoiding the problems with their extend() in JScript (extend is really a cross-cut). Here's an interesting one: document.createElement("blah").toString(); In Mac IE, I think they did something like "[object HTMLBLAHElement", if I remember correctly. Firefox..........."[object HTMLUnknownElement]" Safari............."[object HTMLElement]" IE..................."[object]". I wouldn't mind if the toString did something more than that, for example. providing something like what Firebug does for nodes. <blah/> Garrett > http://lists.w3.org/Archives/Member/member-webapi-cvs/2007Dec/0009.html > > liorean: > > 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. > > That's probably a good idea, and could help simplify some other things > in the spec. > > -- > Cameron McCormack, http://mcc.id.au/ > xmpp:heycam@jabber.org ▪ ICQ 26955922 ▪ MSN cam@mcc.id.au > > -- Monkey, so they say, is the root of all people today.
Received on Monday, 31 December 2007 02:40:00 UTC