-
Notifications
You must be signed in to change notification settings - Fork 29.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
net: refactor self=this to arrow functions #5857
Closed
Closed
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next
Next commit
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: Reviewed-By: Reviewed-By:
- Loading branch information
commit e61380d654cc5553829b4a7ad264e24f33e63982
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -444,23 +444,21 @@ Socket.prototype.destroySoon = function() { | |
Socket.prototype._destroy = function(exception, cb) { | ||
debug('destroy'); | ||
|
||
var self = this; | ||
|
||
function fireErrorCallbacks() { | ||
if (cb) cb(exception); | ||
if (exception && !self._writableState.errorEmitted) { | ||
process.nextTick(emitErrorNT, self, exception); | ||
self._writableState.errorEmitted = true; | ||
if (exception && !this._writableState.errorEmitted) { | ||
process.nextTick(emitErrorNT, this, exception); | ||
this._writableState.errorEmitted = true; | ||
} | ||
} | ||
|
||
if (this.destroyed) { | ||
debug('already destroyed, fire error callbacks'); | ||
fireErrorCallbacks(); | ||
fireErrorCallbacks.call(this); | ||
return; | ||
} | ||
|
||
self._connecting = false; | ||
this._connecting = false; | ||
|
||
this.readable = this.writable = false; | ||
|
||
|
@@ -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; | ||
|
@@ -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.call(this); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here |
||
|
||
if (this._server) { | ||
COUNTER_NET_SERVER_CONNECTION_CLOSE(this); | ||
|
@@ -1080,17 +1078,15 @@ 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 if (options == null || typeof options === 'object') { | ||
options = options || {}; | ||
|
||
if (typeof connectionListener === 'function') { | ||
self.on('connection', connectionListener); | ||
this.on('connection', connectionListener); | ||
} | ||
} else { | ||
throw new TypeError('options must be an object'); | ||
|
@@ -1099,16 +1095,16 @@ function Server(options, 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 | ||
}); | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about just passing
this
to the function and haveself
be the parameter name?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's actually probably a better idea. Thanks.