child_process: refactor self=this in socket_list#5860
child_process: refactor self=this in socket_list#5860benjamingr wants to merge 1 commit intonodejs:masterfrom
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 |
| this.connections--; | ||
|
|
||
| if (self.connections === 0) self.emit('empty'); | ||
| if (this.connections === 0) this.emit('empty', this); |
There was a problem hiding this comment.
Where does the passed this end up here? Seems unnecessary?
There was a problem hiding this comment.
It gets passed to onempty() which is the empty event handler added on line 82.
There was a problem hiding this comment.
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.
@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 = thisin 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.