W3C home > Mailing lists > Public > www-dom@w3.org > January to March 2012

Re: [DOM4] EventTarget as first class citizen

From: Erik Arvidsson <arv@chromium.org>
Date: Wed, 29 Feb 2012 11:59:54 -0800
Message-ID: <CAJ8+Goi_Q0-JLFbjMGmeBeUFVbehyOCK6EK4oZ8EfPfMPb=qGg@mail.gmail.com>
To: Jonas Sicking <jonas@sicking.cc>
Cc: Jake Verbaten <raynos2@gmail.com>, Marcos Caceres <w3c@marcosc.com>, Anne van Kesteren <annevk@opera.com>, www-dom@w3.org
On Wed, Feb 29, 2012 at 11:40, Jonas Sicking <jonas@sicking.cc> wrote:
> I don't see how they could be. Where would the functions store the
> internal state such as the set of event listeners for example?

I don't know about SpiderMonkey but in V8 we can add properties to
Objects that are not visible to script. With ES6 the same thing can be
done with private names.

When you call addEventListener you check if `this` has the property
and if it doesn't you create a new property pointing to the list of
listeners. This is the way we are speccing things for ES6 which allows
us to subclass Date, Map, Set etc.

Another option is to add this hidden property in [[Call]] (or [[Construct]]).

In ES6 style code

let EventTarget;
  let listeners = Name.create();
  EventTarget = function() {};
  EventTarget.prototype = {
    addEventListener(type, listener, capture = false) {
      if (!this[listeners]) this[listeners] = ...
Received on Wednesday, 29 February 2012 20:00:45 UTC

This archive was generated by hypermail 2.3.1 : Tuesday, 20 October 2015 10:46:18 UTC