1/* 2 * Copyright (c) 2024 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15import assert from 'assert'; 16// 不新增变量 17let [PropDemo1, PropDemo2] = ['akria', 12]; 18let { ...reset1 } = { 'name2': 'akria2', age2: 18 }; 19assert(PropDemo1 === 'akria', 'success'); 20assert(PropDemo2 === 12, 'success'); 21assert(reset1.name2 === 'akria2', 'success'); 22assert(reset1.age2 === 18, 'success'); 23function funcLayer() { 24 let [t, u] = ['akria3', 13]; 25 let { ...v } = { 'name2': 'akria4', age2: 20 }; 26 const { PropDemo5: w, PropDemo6: x = 1 } = { PropDemo5: 1, PropDemo6: 2 }; 27 assert(x === 2, 'success'); 28 assert(t === 'akria3', 'success'); 29 assert(u === 13, 'success'); 30 assert(v.name2 === 'akria4', 'success'); 31 assert(v.age2 === 20, 'success'); 32} 33funcLayer(); 34// 新增变量 35let { newName: newName, ...reset3 } = { 'newName': 'akria5', newAge: 20 }; 36assert(newName === 'akria5', 'success'); 37assert(reset3.newAge === 20, 'success'); 38function foo() { 39 return { Propx1: 1, Propy1: 2 }; 40} 41const { Propx1: Propx1, Propy1: Propy1 } = foo(); 42assert(Propx1 === 1, 'success'); 43assert(Propy1 === 2, 'success'); 44let Propx2 = 13; 45let Propy2 = 14; 46const { Propx2: tempX2, Propy2: tempY2 } = { Propx2: Propx2, Propy2: Propy2 }; 47assert(tempX2 === 13, 'success'); 48assert(tempY2 === 14, 'success'); 49