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 <apapirovski@mac.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Franziska Hinkelmann <franziska.hinkelmann@gmail.com>
Reviewed-By: Fedor Indutny <fedor.indutny@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Jan Krems <jan.krems@gmail.com>
Reviewed-By: Evan Lucas <evanlucas@me.com>
Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
Reviewed-By: Benedikt Meurer <benedikt.meurer@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Timothy Gu <timothygu99@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Khaidi Chu <i@2333.moe>
Reviewed-By: Yuta Hiroto <hello@about-hiroppy.com>
Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
  • 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.