arguments是一个类数组对象,包含着传入函数中的所有参数。
slice():接收2个参数(start_index,end_index),返回截取时选定的元素。不会改变原数组 范围左闭右开
function change(){
console.log(arguments); //打印出类数组
//将arguments转成数组,使用数组的forEach遍历方法
var arrArg = Array.prototype.slice.call(arguments,0);
arrArg.forEach(function(item){
console.log(item);
});
console.log(arrArg);
console.log(Array.isArray(arrArg));
//arguments.slice(1,4)//error!
console.log(Array.prototype.slice.call(arguments,1,4)) ;
}
change(3,4,5);
结果: