美文网首页
ES6三点运算符19-10-17

ES6三点运算符19-10-17

作者: 你坤儿姐 | 来源:发表于2019-10-17 09:44 被阅读0次

用途:
1.rest(可变)参数
* 用来取代arguments单笔arguments 灵活,使用三点运算符必须放在最后

   function foo(a, b) {
        console.log(arguments);
       // arguments.callee();//callee属性指向函数本身
   }
foo(2, 65);
//arguments使用arguments打印的是伪数组
1041571275244_.pic.jpg
   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

相关文章

网友评论

      本文标题:ES6三点运算符19-10-17

      本文链接:https://www.haomeiwen.com/subject/mzxmmctx.html