ES6解构赋值
let [va,vb,vc] = [12,'hello',[3,4]];
// va=12, vb='hello',vc=[3,4]
-------------------------------------------------------
默认参数
let [x,y='b',c=true] = ['a',undefined];
// x='a', y='b', c=true
let {x1, y1 = 5, z1 = 3} = {x1: 1, y1: undefined, z1: null};
// x1 = 1, y1= 5, z1= null
也就是说,对象的解构赋值的内部机制,是先找到同名属性,然后再赋给对应的变量。真正被赋值的是后者,而不是前者。
let { foo: baz } = {foo: 'aaa'}
foo//报错 baz// aaa
如果解构模式是嵌套的对象,而且子对象所在的父属性不存在,那么将会报错
let { foo: {baz} } = {baz: 'baz'}
-----------------------------------------------------------------
拓展运算符
let [valueA, valueB, ...valueC] = [1,2,3,4];
// valueA=1, valueB=2, valueC=[3,4]
----------------------------------------------------------------------
数据的归并
let a={x2: 1}, b={y2: 2};
let ab = Object.assign({},a,b);
let newab = {...a,...b};
// ab={x2:1, y2:2} newab={x2:1, y2:2}