Skip to content

Instantly share code, notes, and snippets.

@chrisdickinson
Created April 12, 2011 18:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chrisdickinson/accd13ca4e2e7e92bc78 to your computer and use it in GitHub Desktop.
Save chrisdickinson/accd13ca4e2e7e92bc78 to your computer and use it in GitHub Desktop.
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