Skip to content

Commit a15906c

Browse files
committed
net: refactor self=this to arrow functions
Refactor unused self=this code to code without without this pattern making it more consistent with the rest of our code. PR-URL: #5857 Reviewed-By: Brian White <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Jeremiah Senkpiel <[email protected]> Reviewed-By: Roman Klauke <[email protected]>
1 parent a6b9b55 commit a15906c

File tree

1 file changed

+13
-17
lines changed

1 file changed

+13
-17
lines changed

lib/net.js

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -444,9 +444,7 @@ Socket.prototype.destroySoon = function() {
444444
Socket.prototype._destroy = function(exception, cb) {
445445
debug('destroy');
446446

447-
var self = this;
448-
449-
function fireErrorCallbacks() {
447+
function fireErrorCallbacks(self) {
450448
if (cb) cb(exception);
451449
if (exception && !self._writableState.errorEmitted) {
452450
process.nextTick(emitErrorNT, self, exception);
@@ -456,11 +454,11 @@ Socket.prototype._destroy = function(exception, cb) {
456454

457455
if (this.destroyed) {
458456
debug('already destroyed, fire error callbacks');
459-
fireErrorCallbacks();
457+
fireErrorCallbacks(this);
460458
return;
461459
}
462460

463-
self._connecting = false;
461+
this._connecting = false;
464462

465463
this.readable = this.writable = false;
466464

@@ -472,9 +470,9 @@ Socket.prototype._destroy = function(exception, cb) {
472470
if (this !== process.stderr)
473471
debug('close handle');
474472
var isException = exception ? true : false;
475-
this._handle.close(function() {
473+
this._handle.close(() => {
476474
debug('emit close');
477-
self.emit('close', isException);
475+
this.emit('close', isException);
478476
});
479477
this._handle.onread = noop;
480478
this._handle = null;
@@ -485,7 +483,7 @@ Socket.prototype._destroy = function(exception, cb) {
485483
// to make it re-entrance safe in case Socket.prototype.destroy()
486484
// is called within callbacks
487485
this.destroyed = true;
488-
fireErrorCallbacks();
486+
fireErrorCallbacks(this);
489487

490488
if (this._server) {
491489
COUNTER_NET_SERVER_CONNECTION_CLOSE(this);
@@ -1080,17 +1078,15 @@ function Server(options, connectionListener) {
10801078

10811079
EventEmitter.call(this);
10821080

1083-
var self = this;
1084-
10851081
if (typeof options === 'function') {
10861082
connectionListener = options;
10871083
options = {};
1088-
self.on('connection', connectionListener);
1084+
this.on('connection', connectionListener);
10891085
} else if (options == null || typeof options === 'object') {
10901086
options = options || {};
10911087

10921088
if (typeof connectionListener === 'function') {
1093-
self.on('connection', connectionListener);
1089+
this.on('connection', connectionListener);
10941090
}
10951091
} else {
10961092
throw new TypeError('options must be an object');
@@ -1099,16 +1095,16 @@ function Server(options, connectionListener) {
10991095
this._connections = 0;
11001096

11011097
Object.defineProperty(this, 'connections', {
1102-
get: internalUtil.deprecate(function() {
1098+
get: internalUtil.deprecate(() => {
11031099

1104-
if (self._usingSlaves) {
1100+
if (this._usingSlaves) {
11051101
return null;
11061102
}
1107-
return self._connections;
1103+
return this._connections;
11081104
}, 'Server.connections property is deprecated. ' +
11091105
'Use Server.getConnections method instead.'),
1110-
set: internalUtil.deprecate(function(val) {
1111-
return (self._connections = val);
1106+
set: internalUtil.deprecate((val) => {
1107+
return (this._connections = val);
11121108
}, 'Server.connections property is deprecated.'),
11131109
configurable: true, enumerable: false
11141110
});

0 commit comments

Comments
 (0)