• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2022 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
16declare function print(str:any):string;
17
18var first = 0;
19var second = 1;
20var hundred = "100";
21
22// test array
23var array = [100, "hello"];
24print(array[first]);
25print(array[second]);
26array[first] = "helloworld";
27array[second] = 200;
28print(array[first]);
29print(array[second]);
30
31// test object
32let phrase: { 0: string, "100": string | number, fullPhrase: any } = {
33    0 : "100",
34    "100" : "hello",
35
36    get fullPhrase() {
37        return `${this[first]} ${this[hundred]}`;
38    },
39
40    set fullPhrase(value) {
41        [this[first], this[hundred]] = value.split(" ");
42    }
43};
44print(phrase[first]);
45print(phrase[hundred]);
46phrase[first] = "helloworld";
47phrase[hundred] = 1;
48print(phrase[first]);
49print(phrase[hundred]);
50
51// test getter and setter
52print(phrase.fullPhrase);
53phrase.fullPhrase = "world hello";
54print(phrase.fullPhrase);
55