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 */ 15 16import assert from 'assert'; 17 18// 不新增变量 19let [PropDemo1, PropDemo2] = ['akria', 12]; 20let {...reset1} = {'name2': 'akria2', age2: 18}; 21 22assert(PropDemo1 === 'akria', 'success'); 23assert(PropDemo2 === 12, 'success'); 24assert(reset1.name2 === 'akria2', 'success'); 25assert(reset1.age2 === 18, 'success'); 26 27function funcLayer(){ 28 let [PropDemo3, PropDemo4] = ['akria3', 13]; 29 let {...reset2} = {'name2': 'akria4', age2: 18}; 30 31 assert(PropDemo3 === 'akria3', 'success'); 32 assert(PropDemo4 === 13, 'success'); 33 assert(reset2.name2 === 'akria4', 'success'); 34 assert(reset2.age2 === 18, 'success'); 35} 36funcLayer(); 37 38// 新增变量 39let { newName, ...reset3 } = {'newName': 'akria5', newAge: 18}; 40assert(newName === 'akria5', 'success'); 41assert(reset3.newAge === 18, 'success'); 42 43function foo() { 44 return { Propx1: 1, Propy1: 2 }; 45} 46 47const { Propx1, Propy1 } = foo(); 48assert(Propx1 === 1, 'success'); 49assert(Propy1 === 2, 'success'); 50 51let Propx2 =3; 52let Propy2 =4; 53const { Propx2: tempX2, Propy2: tempY2 } = {Propx2, Propy2} 54assert(tempX2 === 3, 'success'); 55assert(tempY2 === 4, 'success'); 56