<script>
function test(){
var arr = Array.prototype.slice.call(arguments);
//或arr = [].slice.call(arguments);
return arr.reverse();
}
alert(test(1,2,3,4));
</script>
arguments本身为伪数组,不能调用数组的方法,通过call使其能调用数组中的slice方法,从而使其能转为数组。
<script>
function test(){
var arr = Array.prototype.slice.call(arguments);
//或arr = [].slice.call(arguments);
return arr.reverse();
}
alert(test(1,2,3,4));
</script>
arguments本身为伪数组,不能调用数组的方法,通过call使其能调用数组中的slice方法,从而使其能转为数组。