[DOMCore] Re: ECMAScript Object equivalence classes proposal

[Adding DOMCore to the discussion]

Le 02/04/2011 21:16, Brendan Eich a écrit :
> On Apr 2, 2011, at 11:44 AM, David Bruant wrote:
>
>> Hi,
>>
>> This proposal is another attempt to address the DOM Element+EventTarget
>> multiple inheritance issue in ECMAScript.
>
> That issue was resolved by putting EventTarget on the inheritance
> chain. See
>
> http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#node
>
> and
>
> http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html 9.2 DOM Core
>
> "|Node
> <http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#node>| now
> inherits from |EventTarget
> <http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#eventtarget>|.."
>
> In general, WebIDL is not spec'ing multiple "instanceof" inheritance
> any longer. It is explicitly linearizing to work best with JS.
Does it mean that each node within a MathML document will inherit from
EventTarget as well?
Or any node found in any parsed XML document retrieved through
XMLHttpRequest?
I think it does unless you create different "Node" constructors. Tell me
if I'm wrong.


> And instanceof EventTarget is now a non-issue.
In a way, I'm glad it is. However, my point (in the initial thread:
https://mail.mozilla.org/pipermail/es-discuss/2011-April/013537.html)
was more to address the multiple inheritance problem in general and to
take Element (Node, now) and EventTarget as an example of this (I should
have made it clearer, sorry).
A solution has been found for the DOM, but what for other applications
which would have need for multiple inheritance? Should they linearize
their inheritance too?
If another interface is required to be implemented by Nodes, are you
going to force this new interface to inherit from EventTarget or
EventTarget to inherit from it?

I am worried by the sentence "It is explicitly linearizing to work best
with JS."
Are you expecting all application authors to rethink their inheritance
architecture "to work best with JS"? Shouldn't it be the other way
around, namely improve JS to make it a good language to implement what
people need to implement (multiple inheritance as an example)?

We are lucky here and now that there are only two interfaces to inherit
from and that it makes sense in most cases (not all!) that Node inherits
from EventTarget, but it is not a long term solution and it is not
applicable to all situations.

I think that multiple inheritance is a use case that requires a generic
solution.

I agree that my proposal (== being an equivalence relation (for objects
only) and "instanceof" using == instead of === to determine inheritance)
comes with a cost (relatively small in my opinion), but it has the
advantage of providing a very generic response to multiple inheritance.
It has the benefit, for instance to not force all nodes to inherit from
EventTarget for instance.

I wasn't strong on the syntax of my proposal (third optional argument to
Object.create). Any alternative that suits TC39 will be fine to me.
And if there is no good syntax, I think that the multiple inheritance
problem should be addressed in another way anyway.

David

Received on Monday, 4 April 2011 16:57:26 UTC