From 1fc14378dcfdc987b057f0fb93b12d25ff92d33d Mon Sep 17 00:00:00 2001 From: Nicholas Kinsey Date: Mon, 28 May 2012 07:36:38 +1000 Subject: [PATCH 1/3] Aliasing EventEmitter.prototype.removeListener as EventEmitter.prototype.off --- lib/events.js | 2 ++ 1 file changed, 2 insertions(+) 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 = {}; From 9e7f9d43a08f7770f80bc24f5e74debb4e518fea Mon Sep 17 00:00:00 2001 From: Nicholas Kinsey Date: Mon, 28 May 2012 07:38:27 +1000 Subject: [PATCH 2/3] Documenting EventEmitter.prototype.off --- doc/api/events.markdown | 1 + 1 file changed, 1 insertion(+) 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. From c4e5b40acb7e58d54bae74303ff46ef3f69fed91 Mon Sep 17 00:00:00 2001 From: Nicholas Kinsey Date: Mon, 28 May 2012 07:43:26 +1000 Subject: [PATCH 3/3] Testing EventEmitter.prototype.off --- test/simple/test-event-emitter-remove-listeners.js | 4 ++++ 1 file changed, 4 insertions(+) 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;