/* 将函数中的 arguments 类数组转换成 Array */
function argConvert() {
// 在 ES6 之前,需要借助 Array.slice 工具方法
var arr = Array.prototype.slice.call(arguments);
console.log(arr); //(5) [1, 2, 3, 4, 5]
// 在 ES6 中直接转换
var arr1 = Array.from(arguments);
console.log(arr1); //(5) [1, 2, 3, 4, 5]
}
argConvert(1, 2, 3, 4, 5);
JS fun参数转换
最新推荐文章于 2022-06-02 01:05:10 发布