Skip to content

Commit

Permalink
events: add off alias to removeListener
Browse files Browse the repository at this point in the history
Add `off` as an alias for `removeListener`

PR-URL: #17156
Refs: #17102
Reviewed-By: Anatoli Papirovski <[email protected]>
Reviewed-By: Benjamin Gruenbaum <[email protected]>
Reviewed-By: Matteo Collina <[email protected]>
Reviewed-By: Franziska Hinkelmann <[email protected]>
Reviewed-By: Fedor Indutny <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Jan Krems <[email protected]>
Reviewed-By: Evan Lucas <[email protected]>
Reviewed-By: Sakthipriyan Vairamani <[email protected]>
Reviewed-By: Benedikt Meurer <[email protected]>
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Timothy Gu <[email protected]>
Reviewed-By: Michaël Zasso <[email protected]>
Reviewed-By: Khaidi Chu <[email protected]>
Reviewed-By: Yuta Hiroto <[email protected]>
Reviewed-By: Gireesh Punathil <[email protected]>
Reviewed-By: Ruben Bridgewater <[email protected]>
  • Loading branch information
Ulmanb authored and Benjamin Gruenbaum committed Dec 20, 2017
1 parent 482c27e commit 3bb6f07
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
2 changes: 2 additions & 0 deletions lib/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,8 @@ EventEmitter.prototype.removeListener =
return this;
};

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

EventEmitter.prototype.removeAllListeners =
function removeAllListeners(type) {
var listeners, events, i;
Expand Down
3 changes: 2 additions & 1 deletion test/parallel/test-event-emitter-method-names.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@ const events = require('events');
const E = events.EventEmitter.prototype;
assert.strictEqual(E.constructor.name, 'EventEmitter');
assert.strictEqual(E.on, E.addListener); // Same method.
assert.strictEqual(E.off, E.removeListener); // Same method.
Object.getOwnPropertyNames(E).forEach(function(name) {
if (name === 'constructor' || name === 'on') return;
if (name === 'constructor' || name === 'on' || name === 'off') return;
if (typeof E[name] !== 'function') return;
assert.strictEqual(E[name].name, name);
});

0 comments on commit 3bb6f07

Please sign in to comment.