使用 arguments 进行数组分割

function myConcat(separator){
    console.log(arguments);
    var arrays = Array.prototype.slice.call(arguments,1);
    return arrays.join(separator);
};
var arr = myConcat(', ', 'red', 'orange', 'blue');
console.log(arr);// you can also user other separator to slice this arguments conver to a new arrays.


下面介绍其他arguments用法,关于语句:

Array.prototype.slice.call(arguments,1);


以后会介绍更多call和apply的用法,目前了解不太透彻。
□:使用arguments返回一个li列表:
 

function list(type){
    var html = '<' + type + 'l><li>';
    var args = Array.prototype.slice.call(arguments,1);
    html += args.join('</li><li>');
    html += '</li></' + type + 'l>';//end list
    return html;
};
var listHTML = list('u', 'One', 'Two', 'Three');
console.log(listHTML);
/* listHTML is:
// "<ul><li>One</li><li>Two</li><li>Three</li></ul>"
// */


□:使用ES2015的...语法:
 

function foo(...args){
    return args;
}
var arr = foo(1,2,3);
console.log(arr);// [1,2,3]


□:如何update arguments[i]:
 

function func(a){
    arguments[0] = 99;//updating arguments[0] also update a
    console.log(a);
};
func(10);//99
function func(a){
    a = 99; // updating a also updates arguments[0]
    console.log(arguments[0]);
}
func(10);//99
function func(a=55){
    arguments[0] = 99; //updating arguments[0] does not also update a
    console.log(a);
}
func(10);//10
function func(a = 55){
    a = 99;//updating a does not also update arguments[0]
    console.log(arguments[0]);
}
func(10);//10
An untracked default parameter
function func(a=55){
    console.log(arguments[0]);
}
func();// undefined