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 1279adc

Browse filesBrowse files
bsnotervagg
authored andcommitted
timers: optimize callback call: bind -> arrow
ES6 arrow functions are much more efficient than `.bind()` functions. PR-URL: #4038 Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
1 parent 95dd60c commit 1279adc
Copy full SHA for 1279adc

File tree

Expand file treeCollapse file tree

1 file changed

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

1 file changed

+9
-9
lines changed
Open diff view settings
Collapse file

‎lib/timers.js‎

Copy file name to clipboardExpand all lines: lib/timers.js
+9-9Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -192,21 +192,21 @@ exports.setTimeout = function(callback, after) {
192192
case 2:
193193
break;
194194
case 3:
195-
ontimeout = callback.bind(timer, arguments[2]);
195+
ontimeout = () => callback.call(timer, arguments[2]);
196196
break;
197197
case 4:
198-
ontimeout = callback.bind(timer, arguments[2], arguments[3]);
198+
ontimeout = () => callback.call(timer, arguments[2], arguments[3]);
199199
break;
200200
case 5:
201201
ontimeout =
202-
callback.bind(timer, arguments[2], arguments[3], arguments[4]);
202+
() => callback.call(timer, arguments[2], arguments[3], arguments[4]);
203203
break;
204204
// slow case
205205
default:
206206
var args = new Array(length - 2);
207207
for (var i = 2; i < length; i++)
208208
args[i - 2] = arguments[i];
209-
ontimeout = callback.apply.bind(callback, timer, args);
209+
ontimeout = () => callback.apply(timer, args);
210210
break;
211211
}
212212
timer._onTimeout = ontimeout;
@@ -247,20 +247,20 @@ exports.setInterval = function(callback, repeat) {
247247
case 2:
248248
break;
249249
case 3:
250-
ontimeout = callback.bind(timer, arguments[2]);
250+
ontimeout = () => callback.call(timer, arguments[2]);
251251
break;
252252
case 4:
253-
ontimeout = callback.bind(timer, arguments[2], arguments[3]);
253+
ontimeout = () => callback.call(timer, arguments[2], arguments[3]);
254254
break;
255255
case 5:
256256
ontimeout =
257-
callback.bind(timer, arguments[2], arguments[3], arguments[4]);
257+
() => callback.call(timer, arguments[2], arguments[3], arguments[4]);
258258
break;
259259
default:
260260
var args = new Array(length - 2);
261261
for (var i = 2; i < length; i += 1)
262262
args[i - 2] = arguments[i];
263-
ontimeout = callback.apply.bind(callback, timer, args);
263+
ontimeout = () => callback.apply(timer, args);
264264
break;
265265
}
266266
timer._onTimeout = wrapper;
@@ -272,7 +272,7 @@ exports.setInterval = function(callback, repeat) {
272272
return timer;
273273

274274
function wrapper() {
275-
timer._repeat.call(this);
275+
timer._repeat();
276276

277277
// Timer might be closed - no point in restarting it
278278
if (!timer._repeat)

0 commit comments

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