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

> And script libraries will actually use this kinds of event targets without event target chain?

Yes. We have a lot of evidence, e.g. people asking for it on StackOverflow ([1](https://stackoverflow.com/questions/15308371/custom-events-model-without-using-dom-events-in-javascript), [2](https://stackoverflow.com/questions/6635138/is-it-possible-to-dispatch-events-on-regular-objects-not-dom-ones), [3](https://stackoverflow.com/questions/2086956/can-plain-javascript-objects-have-events), [4](https://stackoverflow.com/questions/22186467/how-to-use-javascript-eventtarget), see also linked "related questions" in the sidebar of each), or the fact that the browserify [events package](https://www.npmjs.com/package/events) (which brings Node's hierarchy-less EventEmitter to the browser) is downloaded ~6.5 million times per month.

> But I'd like to hear some reasoning for this, why we need this feature?

I see several big advantages over having people ship their own implementation:

- Less code down the wire, with attendant startup performance and bandwidth benefits
- Provides a common foundation multiple libraries can depend on; currently if you include several libraries, each of which needs event-firing functionality, you can often get multiple event implementations, which can be confusing for consumers in addition to causing code bloat.
- Provides pretty nice semantics compared to most library implementations. In particular, without [self.reportException()](https://github.com/whatwg/html/pull/1196), it's impossible to get the same error-reporting behavior. Most library implementations instead just allow the first throwing listener to block all other listeners, which is not great.

> Do script libraries use event target -like objects in performance critical code? Would using native objects slow them? And if so, would they use native EventTarget?

This is a good question I'm not sure I can answer confidently. I can provide anecdotes from my experience as a web developer, which is that events were not that frequent, being used for signaling "changes" in data or "occurrences" from the outside world or similar. I'd guess maybe between 0-10 per second.

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

Received on Wednesday, 5 July 2017 13:50:26 UTC