ES6 縮寫與解構賦值
縮寫
const kakashi = '卡卡西';
const partner = {
naruto: '鳴人',
sasuke: '佐助',
sakura: '小櫻',
};
const seventhClass = {
kakashi,
partner,
};
console.log(seventhClass);
const kakashi = '卡卡西';
const partner = {
naruto: '鳴人',
sasuke: '佐助',
sakura: '小櫻',
};
const seventhClass = {
kakashi,
...partner,
};
console.log(seventhClass);
解構賦值
let arr = [1, 2, 3];
let [one, two, three] = arr;
console.log(one, two, three);
let one = 2;
let two = 1;
[one, two] = [two, one];
console.log(one, two);
let str = '安安你好嗎';
let [a, b, c, d, e] = str;
console.log(a, b, c, d, e);
let partner = {
naruto: '鳴人',
sasuke: '佐助',
sakura: '小櫻',
};
let { sakura } = partner;
console.log(sakura);
let { naruto: ohMyGod } = partner;
console.log(ohMyGod);
let [one = 3, two = 2] = [1];
console.log(one, two);
let { one = 2, two = 2 } = { one: 1 };
console.log(one, two);
let [x, ...y] = [1, 2, 3];
console.log(x, y);