-
-
Save chrisdickinson/accd13ca4e2e7e92bc78 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/lib/events.js b/lib/events.js | |
index 9e462a0..fe4dde5 100644 | |
--- a/lib/events.js | |
+++ b/lib/events.js | |
@@ -187,6 +187,19 @@ EventEmitter.prototype.removeListener = function(type, listener) { | |
return this; | |
}; | |
+EventEmitter.prototype.removeListeners = function(like) { | |
+ if(typeof(like) === 'function') { | |
+ Object.keys(this._events).forEach(function(key) { | |
+ if(like(key, this[key])) | |
+ delete this[key]; | |
+ }, this._events); | |
+ } else if(like) { | |
+ delete this._events[like]; | |
+ } else { | |
+ this._events = {}; | |
+ } | |
+}; | |
+ | |
EventEmitter.prototype.removeAllListeners = function(type) { | |
// does not use listeners(), so no side effect of creating _events[type] | |
if (type && this._events && this._events[type]) this._events[type] = null; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment