W3C home > Mailing lists > Public > public-webapi@w3.org > June 2007

Re: Prototype chain for objects that implement multiple interfaces

From: Boris Zbarsky <bzbarsky@MIT.EDU>
Date: Wed, 06 Jun 2007 00:15:33 -0500
Message-ID: <466642F5.9040403@mit.edu>
To: public-webapi@w3.org

Cameron McCormack wrote:
> This is probably not what browsers do in practice, though.  For example,
> Opera 9 has an addEventListener method directly on the Node interface
> prototype object

What Gecko does is to put all properties for all the interfaces an object 
implements onto the "closest" prototype object.  So if you have a <div>, 
HTMLDivElement.prototype will have all the properties the <div> is supposed to 
have defined directly on it.

The prototype chain in Gecko basically follows the inheritance model in the DOM 
spec: HTMLDivElement.prototype.[[Prototype]] === HTMLElement.prototype, etc. 
Things like EventTarget are off to the side somewhere as in your imagined way to 
handle it.

As a result, given a <div> object (call it "div"),

   div.[[Prototype]] === HTMLDivElement.prototype
   HTMLDivElement.prototype.[[Prototype]] === HTMLElement.prototype
   div.appendChild === HTMLDivElement.prototype.appendChild

are all true, while

   div.appendChild === HTMLElement.prototype.appendChild

is false.  As a result, to change what the appendChild of a <div> is you have to 
change it on HTMLDivElement.prototype.

Of course all of this is subject to change, and in fact is likely to change some 
time in the not too distant future.

To be honest, do we really think that specifying the exact prototype chain is 
desirable?  How likely are UAs to rework the mappings between their native code 
and ECMAScript to follow said spec?

-Boris
Received on Wednesday, 6 June 2007 05:15:46 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Tuesday, 8 January 2008 14:18:57 GMT