<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<script>
function classA(){
//输出arguments
console.log(arguments)
// 方法一:
var args1 = Array.prototype.slice.call(arguments);
console.log(args1)
//方法二:
var args2= [].slice.call(arguments,0);
console.log(args2);
//方法三:
var args3 = [];
for(var i = 0 , len = arguments.length; i < len ; i++){
args3.push(arguments[i])
}
console.log(args3)
}
classA('tom','19','帅');
</script>
</body>
</html>
将函数的实际参数转换成数组的方法
最新推荐文章于 2021-07-26 15:35:49 发布