Search code examples
javascriptconventions

What's the clearest way to indicate a function uses the 'arguments' object?


What's the best way to indicate a function uses the 'arguments' object?
This is obviously opinion based but are there any conventions? When would it be better to use an array of arguments?

Some examples:

// Function takes n arguments and makes them pretty.
function manyArgs() {
    for (var i = 0; i < arguments.length; i++)
    console.log(arguments[i]);
}

function manyArgs( /* n1 , n2, ... */ )

function manyArgs(n1 /*, n2, ... */ )

function manyArgs(argArray)

Solution

  • // Using ES6 syntax ...
    var foo = function(/*...args*/){
        // shim Array.from, then
        var args = Array.from(arguments);
        // or
        var args = [].slice.call(arguments);
    };