Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit d2b93e5

Browse filesBrowse files
JacksonTianjasnell
authored andcommitted
lib: reduce usage of self = this
Remove unnecessary `self = this`. PR-URL: #5231 Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent f70c71f commit d2b93e5
Copy full SHA for d2b93e5

File tree

Expand file treeCollapse file tree

7 files changed

+36
-46
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

7 files changed

+36
-46
lines changed
Open diff view settings
Collapse file

‎doc/api/stream.markdown‎

Copy file name to clipboardExpand all lines: doc/api/stream.markdown
+2-3Lines changed: 2 additions & 3 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -1026,15 +1026,14 @@ function SimpleProtocol(source, options) {
10261026
// source is a readable stream, such as a socket or file
10271027
this._source = source;
10281028

1029-
var self = this;
10301029
source.on('end', () => {
1031-
self.push(null);
1030+
this.push(null);
10321031
});
10331032

10341033
// give it a kick whenever the source is readable
10351034
// read(0) will not consume any bytes
10361035
source.on('readable', () => {
1037-
self.read(0);
1036+
this.read(0);
10381037
});
10391038

10401039
this._rawHeader = [];
Collapse file

‎lib/dgram.js‎

Copy file name to clipboardExpand all lines: lib/dgram.js
+1-2Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -404,8 +404,7 @@ Socket.prototype.close = function(callback) {
404404
this._stopReceiving();
405405
this._handle.close();
406406
this._handle = null;
407-
var self = this;
408-
process.nextTick(socketCloseNT, self);
407+
process.nextTick(socketCloseNT, this);
409408

410409
return this;
411410
};
Collapse file

‎lib/domain.js‎

Copy file name to clipboardExpand all lines: lib/domain.js
+3-4Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ Domain.prototype._disposed = undefined;
6060
// Called by process._fatalException in case an error was thrown.
6161
Domain.prototype._errorHandler = function errorHandler(er) {
6262
var caught = false;
63-
var self = this;
6463

6564
// ignore errors on disposed domains.
6665
//
@@ -89,13 +88,13 @@ Domain.prototype._errorHandler = function errorHandler(er) {
8988
// as this would throw an error, make the process exit, and thus
9089
// prevent the process 'uncaughtException' event from being emitted
9190
// if a listener is set.
92-
if (EventEmitter.listenerCount(self, 'error') > 0) {
91+
if (EventEmitter.listenerCount(this, 'error') > 0) {
9392
try {
9493
// Set the _emittingTopLevelDomainError so that we know that, even
9594
// if technically the top-level domain is still active, it would
9695
// be ok to abort on an uncaught exception at this point
9796
process._emittingTopLevelDomainError = true;
98-
caught = self.emit('error', er);
97+
caught = this.emit('error', er);
9998
} finally {
10099
process._emittingTopLevelDomainError = false;
101100
}
@@ -111,7 +110,7 @@ Domain.prototype._errorHandler = function errorHandler(er) {
111110
//
112111
// If caught is false after this, then there's no need to exit()
113112
// the domain, because we're going to crash the process anyway.
114-
caught = self.emit('error', er);
113+
caught = this.emit('error', er);
115114
} catch (er2) {
116115
// The domain error handler threw! oh no!
117116
// See if another domain can catch THIS error,
Collapse file

‎lib/https.js‎

Copy file name to clipboardExpand all lines: lib/https.js
+2-3Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,12 +77,11 @@ function createConnection(port, host, options) {
7777
}
7878
}
7979

80-
const self = this;
81-
const socket = tls.connect(options, function() {
80+
const socket = tls.connect(options, () => {
8281
if (!options._agentKey)
8382
return;
8483

85-
self._cacheSession(options._agentKey, socket.getSession());
84+
this._cacheSession(options._agentKey, socket.getSession());
8685
});
8786

8887
// Evict session on error
Collapse file

‎lib/net.js‎

Copy file name to clipboardExpand all lines: lib/net.js
+21-26Lines changed: 21 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -299,9 +299,8 @@ Socket.prototype.read = function(n) {
299299

300300
Socket.prototype.listen = function() {
301301
debug('socket.listen');
302-
var self = this;
303-
self.on('connection', arguments[0]);
304-
listen(self, null, null, null);
302+
this.on('connection', arguments[0]);
303+
listen(this, null, null, null);
305304
};
306305

307306

@@ -883,7 +882,6 @@ Socket.prototype.connect = function(options, cb) {
883882
this._sockname = null;
884883
}
885884

886-
var self = this;
887885
var pipe = !!options.path;
888886
debug('pipe', pipe, options.path);
889887

@@ -893,21 +891,20 @@ Socket.prototype.connect = function(options, cb) {
893891
}
894892

895893
if (typeof cb === 'function') {
896-
self.once('connect', cb);
894+
this.once('connect', cb);
897895
}
898896

899897
this._unrefTimer();
900898

901-
self._connecting = true;
902-
self.writable = true;
899+
this._connecting = true;
900+
this.writable = true;
903901

904902
if (pipe) {
905-
connect(self, options.path);
906-
903+
connect(this, options.path);
907904
} else {
908-
lookupAndConnect(self, options);
905+
lookupAndConnect(this, options);
909906
}
910-
return self;
907+
return this;
911908
};
912909

913910

@@ -1198,11 +1195,10 @@ exports._createServerHandle = createServerHandle;
11981195

11991196
Server.prototype._listen2 = function(address, port, addressType, backlog, fd) {
12001197
debug('listen2', address, port, addressType, backlog, fd);
1201-
var self = this;
12021198

12031199
// If there is not yet a handle, we need to create one and bind.
12041200
// In the case of a server sent via IPC, we don't need to do this.
1205-
if (self._handle) {
1201+
if (this._handle) {
12061202
debug('_listen2: have a handle already');
12071203
} else {
12081204
debug('_listen2: create a handle');
@@ -1227,22 +1223,22 @@ Server.prototype._listen2 = function(address, port, addressType, backlog, fd) {
12271223

12281224
if (typeof rval === 'number') {
12291225
var error = exceptionWithHostPort(rval, 'listen', address, port);
1230-
process.nextTick(emitErrorNT, self, error);
1226+
process.nextTick(emitErrorNT, this, error);
12311227
return;
12321228
}
1233-
self._handle = rval;
1229+
this._handle = rval;
12341230
}
12351231

1236-
self._handle.onconnection = onconnection;
1237-
self._handle.owner = self;
1232+
this._handle.onconnection = onconnection;
1233+
this._handle.owner = this;
12381234

1239-
var err = _listen(self._handle, backlog);
1235+
var err = _listen(this._handle, backlog);
12401236

12411237
if (err) {
12421238
var ex = exceptionWithHostPort(err, 'listen', address, port);
1243-
self._handle.close();
1244-
self._handle = null;
1245-
process.nextTick(emitErrorNT, self, ex);
1239+
this._handle.close();
1240+
this._handle = null;
1241+
process.nextTick(emitErrorNT, this, ex);
12461242
return;
12471243
}
12481244

@@ -1253,7 +1249,7 @@ Server.prototype._listen2 = function(address, port, addressType, backlog, fd) {
12531249
if (this._unref)
12541250
this.unref();
12551251

1256-
process.nextTick(emitListeningNT, self);
1252+
process.nextTick(emitListeningNT, this);
12571253
};
12581254

12591255

@@ -1522,15 +1518,14 @@ Server.prototype.close = function(cb) {
15221518

15231519
Server.prototype._emitCloseIfDrained = function() {
15241520
debug('SERVER _emitCloseIfDrained');
1525-
var self = this;
15261521

1527-
if (self._handle || self._connections) {
1522+
if (this._handle || this._connections) {
15281523
debug('SERVER handle? %j connections? %d',
1529-
!!self._handle, self._connections);
1524+
!!this._handle, this._connections);
15301525
return;
15311526
}
15321527

1533-
process.nextTick(emitCloseNT, self);
1528+
process.nextTick(emitCloseNT, this);
15341529
};
15351530

15361531

Collapse file

‎lib/repl.js‎

Copy file name to clipboardExpand all lines: lib/repl.js
+3-3Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1155,7 +1155,7 @@ function regexpEscape(s) {
11551155
REPLServer.prototype.convertToContext = function(cmd) {
11561156
const scopeVar = /^\s*var\s*([_\w\$]+)(.*)$/m;
11571157
const scopeFunc = /^\s*function\s*([_\w\$]+)/;
1158-
var self = this, matches;
1158+
var matches;
11591159

11601160
// Replaces: var foo = "bar"; with: self.context.foo = bar;
11611161
matches = scopeVar.exec(cmd);
@@ -1164,9 +1164,9 @@ REPLServer.prototype.convertToContext = function(cmd) {
11641164
}
11651165

11661166
// Replaces: function foo() {}; with: foo = function foo() {};
1167-
matches = scopeFunc.exec(self.bufferedCommand);
1167+
matches = scopeFunc.exec(this.bufferedCommand);
11681168
if (matches && matches.length === 2) {
1169-
return matches[1] + ' = ' + self.bufferedCommand;
1169+
return matches[1] + ' = ' + this.bufferedCommand;
11701170
}
11711171

11721172
return cmd;
Collapse file

‎test/parallel/test-zlib.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-zlib.js
+4-5Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -125,11 +125,10 @@ SlowStream.prototype.resume = function() {
125125

126126
SlowStream.prototype.end = function(chunk) {
127127
// walk over the chunk in blocks.
128-
var self = this;
129-
self.chunk = chunk;
130-
self.length = chunk.length;
131-
self.resume();
132-
return self.ended;
128+
this.chunk = chunk;
129+
this.length = chunk.length;
130+
this.resume();
131+
return this.ended;
133132
};
134133

135134

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.