Re: [whatwg/dom] Make EventTarget subclassable (#441)

What about making `addEventListener`, `removeEventListener` and `dispatchEvent` intentionally generic?  This would allow `Object.create` to be used to create event targets too.  All the following could then work:

```javascript
let event = new CustomEvent('foo');

let target1 = new EventTarget();
target1.dispatchEvent(event);

let target2 = Object.create(EventTarget.prototype);
target2.dispatchEvent(event);

let target3 = new (class A extends EventTarget {});
target3.dispatchEvent(event);

let target4 = Object.assign({}, EventTarget.prototype);
target4.dispatchEvent(event);
```

The steps to run through for these methods already make them sound very generic. The only thing that seems to imply otherwise is this sentence in the spec:

> Each EventTarget has an associated list of event listeners.

This could be removed from the spec, with text added to addEventListener to "create an associated list of event listeners for target" if one does not already exist, with dispatchEvent and removeEventListener having a step to "fetch the associated list for target" and abort if null.

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/whatwg/dom/issues/441#issuecomment-301517140

Received on Monday, 15 May 2017 15:49:58 UTC