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

(events): make listenerCount an EventEmitter instance method #25593

Closed
jasonkarns opened this issue Jun 29, 2015 · 3 comments
Closed

(events): make listenerCount an EventEmitter instance method #25593

jasonkarns opened this issue Jun 29, 2015 · 3 comments

Comments

@jasonkarns
Copy link
Member

listenerCount is currently a class method on EventEmitter, yet the very first argument is the emitter instance whose listenerCount should be returned. Why, then, is it a class method at all if it requires an instance on which to operate?

I propose EventEmitter.prototype.listenerCount be added such that:

var emitter = new require('events').EventEmitter();

EventEmitter.listenerCount(emitter, 'myEvent');
// alias for:
emitter.listenerCount('myEvent');
@brendanashworth
Copy link

It was to avoid breakage for users extending the EventEmitter, I'm pretty sure. You can find discussion over here: nodejs/node#734.

@jasonkarns
Copy link
Member Author

@brendanashworth thanks, I hadn't seen that particular one. I still think it's quite crazy to permanently lock an API from improving simply because people inherit. That's the cost of inheritance, and those who do so should be aware of what follows.

Even though it's an API addition (which would normally only warrant a minor version bump), if it strikes people has a backwards incompatible change, then push it with a major version.

@jasnell
Copy link
Member

jasnell commented Jul 10, 2015

This API is not going to change in v0.12 so I'm going to close this here. If a change needs to be made to the API, then the best place to pursue that is either nodejs/io.js or nodejs/node.

@jasnell jasnell closed this as completed Jul 10, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants