Skip to content

Commit

Permalink
net: refactor self=this to arrow functions
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
benjamingr authored and Myles Borins committed Apr 5, 2016
1 parent e966d1f commit f3f19ee
Showing 1 changed file with 13 additions and 17 deletions.
30 changes: 13 additions & 17 deletions lib/net.js
Original file line number Diff line number Diff line change
Expand Up @@ -444,9 +444,7 @@ Socket.prototype.destroySoon = function() {
Socket.prototype._destroy = function(exception, cb) {
debug('destroy');

var self = this;

function fireErrorCallbacks() {
function fireErrorCallbacks(self) {
if (cb) cb(exception);
if (exception && !self._writableState.errorEmitted) {
process.nextTick(emitErrorNT, self, exception);
Expand All @@ -456,11 +454,11 @@ Socket.prototype._destroy = function(exception, cb) {

if (this.destroyed) {
debug('already destroyed, fire error callbacks');
fireErrorCallbacks();
fireErrorCallbacks(this);
return;
}

self._connecting = false;
this._connecting = false;

this.readable = this.writable = false;

Expand All @@ -472,9 +470,9 @@ Socket.prototype._destroy = function(exception, cb) {
if (this !== process.stderr)
debug('close handle');
var isException = exception ? true : false;
this._handle.close(function() {
this._handle.close(() => {
debug('emit close');
self.emit('close', isException);
this.emit('close', isException);
});
this._handle.onread = noop;
this._handle = null;
Expand All @@ -485,7 +483,7 @@ Socket.prototype._destroy = function(exception, cb) {
// to make it re-entrance safe in case Socket.prototype.destroy()
// is called within callbacks
this.destroyed = true;
fireErrorCallbacks();
fireErrorCallbacks(this);

if (this._server) {
COUNTER_NET_SERVER_CONNECTION_CLOSE(this);
Expand Down Expand Up @@ -1078,33 +1076,31 @@ function Server(options, connectionListener) {

EventEmitter.call(this);

var self = this;

if (typeof options === 'function') {
connectionListener = options;
options = {};
self.on('connection', connectionListener);
this.on('connection', connectionListener);
} else {
options = options || {};

if (typeof connectionListener === 'function') {
self.on('connection', connectionListener);
this.on('connection', connectionListener);
}
}

this._connections = 0;

Object.defineProperty(this, 'connections', {
get: internalUtil.deprecate(function() {
get: internalUtil.deprecate(() => {

if (self._usingSlaves) {
if (this._usingSlaves) {
return null;
}
return self._connections;
return this._connections;
}, 'Server.connections property is deprecated. ' +
'Use Server.getConnections method instead.'),
set: internalUtil.deprecate(function(val) {
return (self._connections = val);
set: internalUtil.deprecate((val) => {
return (this._connections = val);
}, 'Server.connections property is deprecated.'),
configurable: true, enumerable: false
});
Expand Down

0 comments on commit f3f19ee

Please sign in to comment.