[webkit-dev] JS bindings: Adding EventTarget to the prototype chain

Cameron McCormack cam at mcc.id.au
Thu Jun 9 22:28:50 PDT 2011

Maciej Stachowiak:
> I don't have a personal opinion on which way is technically better
> myself. But I think the key is getting our code aligned with where
> standards are going, wether by changing he code or the standards.
> EventTarget in the prototype chain seems neither especially awesome
> nor especially terrible to me, it is not really clear to me why
> editor's drafts of the listed specs decided to change.

I remember it being discussed at the TC39 meeting in November, as part
of the general discussion we had about removing multiple inheritance
from Web IDL.  (It might not’ve been on the day that Sam was in the
room, though.)  EventTarget was brought up as the “mixin” that would
probably want to have global monkeypatching done to it the most, and a
suggestion was made to make interfaces like Node inherit from it.

We do have https://bugzilla.mozilla.org/show_bug.cgi?id=612980 to make
this change, too.

With the very-soon-to-be-rewritten Web IDL single inheritance, if we
just keep

  interface Node { ... };
  interface EventTarget { ... };
  Node implements EventTarget;

then we lose the (future) ability to do

  var ael = EventTarget.prototype.addEventListener;
  EventTarget.prototype.addEventListener = function(a, b, c) {
    // do some logging
    ael.call(this, a, b, c);

and have it affect all EventTargets, but you would still be able to get
at Node.prototype.addEventListener (i.e., more easily than with the
currently specified mixin prototype objects).  So it’s probably not a
great loss if we didn’t go ahead with Node inheriting from EventTarget.

If there’s not a strong desire to implement this change, can someone
bring it up on www-dom at w3.org?

Cameron McCormack ≝ http://mcc.id.au/

More information about the webkit-dev mailing list