类数组:无法直接调用数组方法或期望length属性有什么特殊的行为,但仍可以对真正数组遍历方法来遍历它们。典型的是函数的 argument参数,还有像调用getElementsByTagName,document.childNodes之类的,它们都返回 NodeList对象都属于类数组。可以使用Array.prototype.slice.call(伪数组名)将数组转化为真正的Array 对象。
function reWriteArgument(){
//为了使用unshift数组方法,将argument转化为真正的数组,函数由一个属性arguments,用来保存函数的形参
var args = Array.prototype.slice.call(arguments);
args.shift(args[0]);
return args;
};
console.log(reWriteArgument(1,2));