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
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 @@ -48,6 +48,7 @@ it is removed.
});

### 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 @@ -222,6 +222,8 @@ EventEmitter.prototype.removeListener = function(type, listener) {
return this;
};

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

EventEmitter.prototype.removeAllListeners = function(type) {
if (arguments.length === 0) {
this._events = {};
Expand Down
4 changes: 4 additions & 0 deletions test/simple/test-event-emitter-remove-listeners.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ var common = require('../common');
var assert = require('assert');
var events = require('events');

var e = new events.EventEmitter();

// sanity check
assert.equal(e.removeListener, e.off);

var count = 0;

Expand Down