>》>》>》>》

es6函数扩展(+ ...扩展运算符)

1、参数默认值

 function foo(param = 'nihao'){
   console.log(param);
 }
 foo('hello kitty');
2、参数解构赋值
 function foo({ uname='lisi' , age=13 }={}){
     console.log(uname,age);
 }
foo({ uname:'zhangsan'  , age:15 });
3、rest参数(剩余参数)
function foo(a,b,...param){
     console.log(a);
     console.log(b);
     console.log(param);
 }

 foo(1,2,3,4,5);
//param = [3,4,5]
4、扩展运算符...
function foo(a,b,c,d){
    console.log(a + b + c + d );
}

let arr = [1,2,3,4];

// foo.apply(null,arr);

foo(...arr);
//自动把arr数组展开当参数传递,打印10

// 合并数组
let arr1 = [1,2,3];
let arr2 = [4,5,6];
let arr3 = [...arr1,...arr2];
console.log(arr3);
//arr3 = [1,2,3,4,5,6]

 

posted @ 2019-07-16 16:46  大、锤  阅读(1440)  评论(0编辑  收藏  举报