Re: Prototype chain for objects that implement multiple interfaces

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 UTC