Rest options allow you to optimize?

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);
        }
    };
}
+6
1

arguments , , . , () - , :

function modify(arr) {
    arr[0] = 3;
}

(function (a) {
    console.log('arguments is an ' + arguments.constructor.name);
    console.log('a is ', a);
    modify(arguments);
    console.log('after calling modify, a is ', a);
})(0); 

. .

, , , .

, , , , , :

(function (...args) {
    console.log('args is an ' + args.constructor.name);
})(0); 

( ) , arguments ...args.

. arguments , , arguments, JavaScript:

function modify(arr) {
    arr[0] = 3;
}

(function (a) {
    "use strict"; // <-----
    console.log('In strict mode');
    console.log('arguments is still an ' + arguments.constructor.name);
    console.log('a is ', a);
    modify(arguments);
    console.log('after calling modify, a is still ', a);
})(0); 

mdn :

arguments, . , arg, arg arguments[0], ( arguments[0]). arguments . arguments[i] , arguments[i].

+4

All Articles