From 3bb6f07d528905d2ba6b9a4710890bc74350d7f0 Mon Sep 17 00:00:00 2001 From: Ulmanb Date: Mon, 20 Nov 2017 20:24:15 +0200 Subject: [PATCH] events: add off alias to removeListener MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add `off` as an alias for `removeListener` PR-URL: https://github.com/nodejs/node/pull/17156 Refs: https://github.com/nodejs/node/issues/17102 Reviewed-By: Anatoli Papirovski Reviewed-By: Benjamin Gruenbaum Reviewed-By: Matteo Collina Reviewed-By: Franziska Hinkelmann Reviewed-By: Fedor Indutny Reviewed-By: James M Snell Reviewed-By: Jan Krems Reviewed-By: Evan Lucas Reviewed-By: Sakthipriyan Vairamani Reviewed-By: Benedikt Meurer Reviewed-By: Anna Henningsen Reviewed-By: Timothy Gu Reviewed-By: Michaƫl Zasso Reviewed-By: Khaidi Chu Reviewed-By: Yuta Hiroto Reviewed-By: Gireesh Punathil Reviewed-By: Ruben Bridgewater --- lib/events.js | 2 ++ test/parallel/test-event-emitter-method-names.js | 3 ++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/events.js b/lib/events.js index b9149d2b9b51a7..28a8c4228b3169 100644 --- a/lib/events.js +++ b/lib/events.js @@ -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; diff --git a/test/parallel/test-event-emitter-method-names.js b/test/parallel/test-event-emitter-method-names.js index c74b88aff7acf2..684024d0276261 100644 --- a/test/parallel/test-event-emitter-method-names.js +++ b/test/parallel/test-event-emitter-method-names.js @@ -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); });