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 16class A { 17 name: string = "A"; 18 id: number = 0; 19 get getName(): string { 20 return this.name; 21 } 22 get getId(): number { 23 return this.id; 24 } 25 set setName(name: string) { 26 this.name = name; 27 } 28 set setId(id: number) { 29 this.id = id; 30 } 31 constructor() { 32 this.id = 95; 33 } 34 dump(): string { 35 let msg: string = this.name + ":" + this.id; 36 return msg; 37 } 38 static a: number = 1; 39 a: number = 2; 40 static stest(): void { 41 console.log(this.a); 42 } 43 test(): void { 44 console.log(this.a); 45 } 46 testwiththis(this: A): void { 47 console.log(this.a); 48 } 49} 50 51function add(x: number, y: number): number { 52 let z: number = x + y; 53 this.z = z; 54 return z; 55} 56