-
Notifications
You must be signed in to change notification settings - Fork 29.7k
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
child_process: refactor self=this in socket_list #5860
child_process: refactor self=this in socket_list #5860
Conversation
The socket list module (used by child_process) currently uses the `var self = this;` pattern for context in several places, this PR replaces this with arrow functions or passing a parameter in where appropriate. Note that the `var self = this` in the _request is intentioanlly left in place since it is not trivial to refactor it and the current pattern isn't bad given the use case. PR-URL: Reviewed-By: Reviewed-By:
LGTM if CI is ok: https://ci.nodejs.org/job/node-test-pull-request/2039/ |
LGTM, and CI is green. |
LGTM, CI is green |
|
||
if (self.connections === 0) self.emit('empty'); | ||
if (this.connections === 0) this.emit('empty', this); |
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.
Where does the passed this
end up here? Seems unnecessary?
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.
It gets passed to onempty()
which is the empty
event handler added on line 82.
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.
To send the context as a parameter seems ambigous. Since we are using arrow functions, why not just binding the method l.82 ? onempty.bind(this)
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.
@ludoblues bind
is slow and it makes the resulting function slow too. It is also very scarcely used in Node where this pattern is very common. See http://stackoverflow.com/questions/17638305/why-is-bind-slower-than-a-closure
Landed in a6b9b55 |
The socket list module (used by child_process) currently uses the `var self = this;` pattern for context in several places, this PR replaces this with arrow functions or passing a parameter in where appropriate. Note that the `var self = this` in the _request is intentioanlly left in place since it is not trivial to refactor it and the current pattern isn't bad given the use case. PR-URL: #5860 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Brian White <mscdex@mscdex.net>
The socket list module (used by child_process) currently uses the `var self = this;` pattern for context in several places, this PR replaces this with arrow functions or passing a parameter in where appropriate. Note that the `var self = this` in the _request is intentioanlly left in place since it is not trivial to refactor it and the current pattern isn't bad given the use case. PR-URL: #5860 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Brian White <mscdex@mscdex.net>
The socket list module (used by child_process) currently uses the `var self = this;` pattern for context in several places, this PR replaces this with arrow functions or passing a parameter in where appropriate. Note that the `var self = this` in the _request is intentioanlly left in place since it is not trivial to refactor it and the current pattern isn't bad given the use case. PR-URL: #5860 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Brian White <mscdex@mscdex.net>
The socket list module (used by child_process) currently uses the `var self = this;` pattern for context in several places, this PR replaces this with arrow functions or passing a parameter in where appropriate. Note that the `var self = this` in the _request is intentioanlly left in place since it is not trivial to refactor it and the current pattern isn't bad given the use case. PR-URL: #5860 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Brian White <mscdex@mscdex.net>
Pull Request check-list
Affected core subsystem(s)
child_process
Description of change
The socket list module (used by child_process) currently uses the
var self = this;
pattern for context in several places, this PR replaces this with arrow functions or passing a parameter in where appropriate.Note that the
var self = this
in the _request is intentionally left in place since it is not trivial to refactor it and the current pattern isn't bad given the use case.