用途:
1.rest(可变)参数
* 用来取代arguments单笔arguments 灵活,使用三点运算符必须放在最后
function foo(a, b) {
console.log(arguments);
// arguments.callee();//callee属性指向函数本身
}
foo(2, 65);
//arguments使用arguments打印的是伪数组

function foo(a,...value){
console.log(value);//在三个点前面添加一个值之后,只打印排除第一个之后的值,依次类推,但是使用三点运算符的值必须放在最后
value.forEach(function (item, index){
console.log(item, index);
})
}
foo(2, 65,33,44);//此时打印出来的是真数组,真数组中有很多方法,如forEach
2.扩展参数
let arr = [1, 6];
let arr1 = [2,3,4,5];
arr = [1,...arr1,6];
console.log(arr);//打印结果[1,2,3,4,5,6]
console.log(...arr);//打印结果1 2 3 4 5 6
网友评论