数组解构
{
let a = 1;
let b = 2;
[a, b] = [b, a];
console.log(a, b);
}
{
function f(){
return [1, 2, 3];
}
let a, b, c;
[a, b, c] = f();
[a, ...b] = f();
}
对象赋值
{
let o={p:42, q:true};
let {p, q} = o;
console.log(p,q);
}
{
let {a=10, b=5} = {a:3};
console.log(a, b);
}
{
let metaData = {
title: 'hello',
test:[{
title:'test',
desc:'kiwi'
}]
}
let {title:esTitls, test:[{title:cnTitle}]} = metaData;
console.log(esTitls, cnTitle);
}
对象赋值
{
let [a,b,c,d,e] = 'hello';
console.log(a,b,c,d,e);
let {length} = 'hello';
console.log(length);
}