es6基础(7)--函数扩展

 1 {
 2     //有默认值的后面如果有参数必须要有默认值
 3     function test(x,y="world"){
 4         console.log(x,y)
 5     }
 6     test('hello');//hello world
 7     test('hello',"kill");//hello kill
 8 
 9 }
10 {
11     let x='test';
12     function test2(x,y=x){
13         console.log('作用域',x,y);
14     }
15     test2('kill');//kill kill
16     function test3(c,y=x){
17         console.log('作用域',c,y);
18     }
19     test3('kill');//kill test
20 }
21 {
22     //如果参数是arg,不可以有其他参数
23     function test3(...arg){
24         for(let v of arg){
25             console.log('rest',v);
26         }
27     }
28     test3(1,2,3,4,'a');
29 }
30 {
31     console.log(...[1,2,4]);//1 2 4
32     console.log('a',...[1,2,4]);//a 1 2 4
33 }
34 //箭头函数
35 {
36     //  函数名  参数  返回值
37     let arrow = v => v*2;
38     console.log(arrow(3));//6
39 
40     let arrow2=()=>5;
41     console.log(arrow2())
42 }

猜你喜欢

转载自www.cnblogs.com/chenlw/p/9210098.html