/**解构 是ES6的新特性*/ export class SpreadExample { execute(): void { //---------------解构数组------------------// let datas = [1, 2]; let [value1, value2] = datas; console.log(value1, value2); //可以很方便的交换数据 let arr1 = [1, 2, 3]; let arr2 = [10, 20, 30]; //传递键值(0,1)解构数组 [arr2, arr1] = [arr1, arr2]; console.log(arr1, arr2); //解构剩余参数 let [first, ...rest] = [1, 2, 3, 4, 5]; console.log(first); console.log(rest); //---------------解构对象------------------// let states = { width: 100, height: 200 }; //传递健值(width,height)解构状态 const { width, height } = states; console.log(width, height); //可以重命名解构名字(:后面是类型) const { width: widthRename, height: heighRename }: { width: number, height: number } = states; console.log(widthRename, heighRename); } }