Array.prototype.slice.call(arguments)能将具有length属性的对象转换成数组,除了IE下的节点集合(因为ie下的dom对象是以com对象的形式实现的,js对象与com对象不能进行转换)
<script type="text/javascript"> var a={length:2, 0:"first", 1:"second"}; console.log(Array.prototype.slice.call(a,0));//输出["first", "second"] var a={length:2, 0:"first", 1:"second"}; console.log(Array.prototype.slice.call(a,1));//输出["second"] var a={0:"first", 1:"second"};//去掉length属性, 返回一个空数组 console.log(Array.prototype.slice.call(a,0));//输出[] function test(){ console.log(Array.prototype.slice.call(arguments,0));//输出["a", "b", "c"] console.log(Array.prototype.slice.call(arguments,1));//输出["b", "c"] } test("a","b","c"); var a={0:"first", 1:"second"}; function test(){ console.log(Array.prototype.slice.call(arguments,0));//输出[Object] console.log(Array.prototype.slice.call(arguments,1));//输出[] } test(a); </script>