Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

events: Alias EventEmitter.protoype.removeListener as EventEmitter.prototype.off #540

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/api/events.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ it is removed.
Returns emitter, so calls can be chained.

### emitter.removeListener(event, listener)
### emitter.off(event, listener)

Remove a listener from the listener array for the specified event.
**Caution**: changes array indices in the listener array behind the listener.
Expand Down
2 changes: 2 additions & 0 deletions lib/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,8 @@ EventEmitter.prototype.removeListener =
return this;
};

EventEmitter.prototype.off = EventEmitter.prototype.removeListener;

EventEmitter.prototype.removeAllListeners =
function removeAllListeners(type) {
var key, listeners;
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-event-emitter-method-names.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ var E = events.EventEmitter.prototype;
assert.equal(E.constructor.name, 'EventEmitter');
assert.equal(E.on, E.addListener); // Same method.
Object.getOwnPropertyNames(E).forEach(function(name) {
if (name === 'constructor' || name === 'on') return;
if (name === 'constructor' || name === 'on' || name === 'off') return;
if (typeof E[name] !== 'function') return;
assert.equal(E[name].name, name);
});
3 changes: 3 additions & 0 deletions test/parallel/test-event-emitter-remove-listeners.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,6 @@ e4.on('removeListener', common.mustCall(function(name, cb) {
e4.on('quux', remove1);
e4.on('quux', remove2);
e4.removeListener('quux', remove1);

var e5 = new events.EventEmitter();
assert.equal(e5.removeListener, e5.off);