Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

Aliasing EventEmitter.prototype.removeListener as EventEmitter.prototype.off #3338

Closed
wants to merge 3 commits into from
Closed

Aliasing EventEmitter.prototype.removeListener as EventEmitter.prototype.off #3338

wants to merge 3 commits into from

Conversation

525c1e21-bd67-4735-ac99-b4b0e5262290

I understand the API of events is frozen but EventEmitters should have removeListener aliased as off just as they have addListener aliased as on

@525c1e21-bd67-4735-ac99-b4b0e5262290

http://search.npmjs.org/#/events-off will polyfill this for now.

@isaacs
Copy link

isaacs commented May 28, 2012

This is kind of cute, the way "on" and "off" are kind of like antonyms, but it reads weird. ee.off('event', handler)

-1 on this. I could be convinced if a lot of people want it, but it seems like event handler removal is rare enough that removeListener isn't so terrible, and it seems best to not touch events.js for anything that isn't a serious bug or performance issue.

@isaacs isaacs closed this May 28, 2012
@domenic
Copy link

domenic commented May 28, 2012

I could be convinced if a lot of people want it

In that case, +1? It's a pretty common pattern in other event-related libraries (EventEmitter2 and jQuery/Zepto being the biggest I can think of). Coming from client-side, I tried off first, and when it didn't work, had to go consult the docs to find removeListener.

event handler removal is rare enough

I was under the impression it was necessary to prevent memory leaks? E.g. when working with streams.

@tjconcept
Copy link

+1
Tried .off as well.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants