1 //解构赋值
 2 
 3 {
 4     let a,b,rest;
 5     [a,b]=[1,2];
 6     console.log(a,b);
 7 }
 8 //数组解构赋值
 9 {
10     let a,b,rest;
11     [a,b,...rest]=[1,2,3,4,5,6];
12     console.log(a,b,rest);
13 }
14 //对象解构赋值
15 {
16     let a,b;
17     ({a,b}={a:1,b:2})
18     console.log(a,b);
19 }
20 
21 {
22     let a,b,c,rest;
23     [a,b,c=3]=[1,2];
24     console.log(a,b,c);
25 }
26 //变量交换
27 {
28     let a=1;
29     let b=2;
30     [a,b]=[b,a];
31     console.log(a,b);
32 }
33 
34 {
35     function f(){
36         return [1,2]
37     }
38     let a,b;
39     [a,b]=f();
40     console.log(a,b)
41 }
42 {
43     function f(){
44         return [1,2,3,4,5,6];
45     }
46     let a,b,c;
47     [a,,,b]=f();
48     console.log(a,b);
49 }
50 //当只要数组内的某几个的时候
51 {
52     function f(){
53         return [1,2,3,4,5,6];
54     }
55     let a,b,c;
56     [a,...b]=f();
57     console.log(a,b);
58 }
59 //对象的赋值
60 {
61     let o={p:42,q:true};
62     let {p,q}=o;
63     console.log(p,q);
64 }
65 {
66     let {a=10,b=5}={a:3};
67     console.log(a,b);
68 }
69 {
70     let metaData={
71         title:'abc',
72         test:[{
73             title:'test',
74             desc:'description'
75         }]
76     }
77     let {title:esTitle,test:[{title:cntitle}]}=metaData;
78     console.log(esTitle,cntitle);
79 }

 

posted on 2018-06-21 13:33  chenlw101  阅读(129)  评论(0编辑  收藏  举报