no need to copy arguments for apply, see petkaantonov/bluebird#1389

This commit is contained in:
Jare Guo
2017-05-17 17:46:51 +08:00
parent 2083603d80
commit 3fcd0c8b46
2 changed files with 4 additions and 12 deletions
+2 -6
View File
@@ -134,18 +134,14 @@ function debounce (func, wait, immediate) {
if (callNow) func.apply(context, args);
} : function () {
var context = this;
var args = new Array(arguments.length);
for (var i = 0; i < arguments.length; i++) {
args[i] = arguments[i];
}
var later = function() {
timeout = null;
if (!immediate) func.apply(context, args);
if (!immediate) func.apply(context, arguments);
};
var callNow = immediate && !timeout;
clearTimeout(timeout);
timeout = setTimeout(later, wait);
if (callNow) func.apply(context, args);
if (callNow) func.apply(context, arguments);
};
}
+2 -6
View File
@@ -47,18 +47,14 @@ function debounce (func, wait, immediate) {
if (callNow) func.apply(context, args);
} : function () {
var context = this;
var args = new Array(arguments.length);
for (var i = 0; i < arguments.length; i++) {
args[i] = arguments[i];
}
var later = function() {
timeout = null;
if (!immediate) func.apply(context, args);
if (!immediate) func.apply(context, arguments);
};
var callNow = immediate && !timeout;
clearTimeout(timeout);
timeout = setTimeout(later, wait);
if (callNow) func.apply(context, args);
if (callNow) func.apply(context, arguments);
};
}