diff --git a/doc/api/events.markdown b/doc/api/events.markdown index fed957d3450..3a898aedf3a 100644 --- a/doc/api/events.markdown +++ b/doc/api/events.markdown @@ -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. diff --git a/lib/events.js b/lib/events.js index c4ab9d80a0a..9432cafe225 100644 --- a/lib/events.js +++ b/lib/events.js @@ -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 = {}; diff --git a/test/simple/test-event-emitter-remove-listeners.js b/test/simple/test-event-emitter-remove-listeners.js index 33ee3df564f..a222f8d140f 100644 --- a/test/simple/test-event-emitter-remove-listeners.js +++ b/test/simple/test-event-emitter-remove-listeners.js @@ -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;