Re: [whatwg/dom] [Proposal] Add EventTarget.getEventListeners() (#412)

@LeaVerou 

> Regardless of the characterization of these arguments, it's a false sense of security, since this is possible today by wrapping `addEventListener`. There are libraries that do this. However, I think we both agree that there's a multitude of reasons why this is better done natively than having a library hijack `addEventListener`, right?

Just my two cents here, but I disagree. As has been pointed out, once you can enumerate event listeners, you can implement something like Node's [`removeAllListeners`](https://nodejs.org/api/events.html#events_emitter_removealllisteners_eventname), which warns

> Note that it is bad practice to remove listeners added elsewhere in the code, particularly when the EventEmitter instance was created by some other component or module (e.g. sockets or file streams).

In practice, I've found this means that, as a library author, if you vend event-emitting objects to your users whose events you also use to drive internal functionality, you need to separate the EventEmitter interface your users will depend on from the one your internal functionality depends on (otherwise, a `removeAllListeners` call could break you, and it's annoying to document around…). I would not like to see the DOM APIs follow suit, and I would prefer encapsulation over convenience in this case.

-- 
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/412#issuecomment-280730077

Received on Friday, 17 February 2017 18:34:31 UTC