The management argumentssection of the Bluebird article on optimization killers states that:
The object argumentsshould not be transmitted or leaked anywhere.
In other words, do not do the following:
function leaky(){
return arguments;
}
But do it:
function not_leaky(){
var i = arguments.length,
args = [];
while(i--) args[i] = arguments[i];
return args;
}
With the introduction of Rest paramters , passing the remaining array of parameters still causes optimization problems? Based on what I understand, the problem is that we cannot let the actual argumentsObject free. The final, specific copies are argumentsin order, but not the actual object itself. If so, is the argument of the rest considered OK and an optimized copy argumentswhen used as follows?
function maybe_optimizable(...args){
return args;
}
, debounce debounce ( Underscore.js), , arguments debounce. , :
function debounce(func, wait, immediate) {
let timeout;
return function (...args) {
let context = this,
now = immediate && !timeout;
clearTimeout(timeout);
timeout = setTimeout(() => {
timeout = null;
if (!immediate) {
func.apply(context, args);
}
}, wait);
if (now) {
func.apply(context, args);
}
};
}