Browse Source

events: remove unnecessary checks

This commit removes two truthy checks for object properties that
are immediately followed by a strict equality check. The other
item in the comparison is guaranteed to be a function by this
point in the code, so the truthy check is redundant.

PR-URL: https://github.com/nodejs/node/pull/9330
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
v6
cjihrig 8 years ago
parent
commit
7f909c3b79
  1. 5
      lib/events.js

5
lib/events.js

@ -327,7 +327,7 @@ EventEmitter.prototype.removeListener =
if (!list) if (!list)
return this; return this;
if (list === listener || (list.listener && list.listener === listener)) { if (list === listener || list.listener === listener) {
if (--this._eventsCount === 0) if (--this._eventsCount === 0)
this._events = new EventHandlers(); this._events = new EventHandlers();
else { else {
@ -339,8 +339,7 @@ EventEmitter.prototype.removeListener =
position = -1; position = -1;
for (i = list.length; i-- > 0;) { for (i = list.length; i-- > 0;) {
if (list[i] === listener || if (list[i] === listener || list[i].listener === listener) {
(list[i].listener && list[i].listener === listener)) {
originalListener = list[i].listener; originalListener = list[i].listener;
position = i; position = i;
break; break;

Loading…
Cancel
Save