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

Re: Prototype chain for objects that implement multiple interfaces

From: Maciej Stachowiak <mjs@apple.com>
Date: Wed, 6 Jun 2007 01:12:05 -0700
Cc: public-webapi@w3.org
Message-Id: <A22E3157-CF93-4693-9A68-D46124B24EF9@apple.com>
To: Boris Zbarsky <bzbarsky@mit.edu>

On Jun 5, 2007, at 10:15 PM, Boris Zbarsky wrote:

> 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.

In WebKit, this would be true.

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

Generally, we make the same prototype chain you describe, but we put  
methods on the JS [[Class]] that defines them. In cases of multiple  
interfaces or multiple inheritance, we fold the set of methods into  
the next concrete class to inherit from the interfaces.

> 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?

If we thought it would improve compatibility we would be open to  
changing this for WebKit. Sites hack the prototypes often enough that  
we had to add stuff like HTMLElement.prototype to our Window object,  
originally we did not have it and the standard is pretty unclear on  
whether it should exist.

To give a specific example, it could be a problem that replacing  
HTMLElement.prototype.addEventListener will affect <div> elements in  
WebKit but not in Gecko, based on what you describe.

Received on Wednesday, 6 June 2007 08:12:13 UTC

This archive was generated by hypermail 2.3.1 : Tuesday, 6 January 2015 21:16:23 UTC