1/* 2 * Copyright (c) 2025 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 16 17// anonymous 18let anonymous = () => { 19 print('this is anonymous function'); 20}; 21globalThis.testAnonymous = anonymous; 22 23// function 24function test() { 25 print('this is test function'); 26} 27globalThis.testFunction = test; 28 29function ObjectFun() { 30 print('this is objectFun function'); 31} 32 33class Person { 34 constructor(name, age) { 35 this.name = name; 36 this.age = age; 37 } 38 39 greet() { 40 print(`Hello, my name is ${this.name} and I'm ${this.age} years old.`); 41 } 42} 43 44 45//object 46let obj = { 47 objectClass: new Person('Alice', 25), 48 objFun: new ObjectFun(), 49 50 testObject() { 51 objFun(); 52 let name = objectClass.name; 53 print('this object name is JSObject'); 54 } 55 56}; 57globalThis.testObj = obj; 58 59// class 60class Student { 61 constructor(name, grade) { 62 this.name = name; 63 this.grade = grade; 64 } 65 66 getMessage() { 67 print(`Hello, his name is ${this.name} and he's in ${this.grade} grade.`); 68 } 69} 70globalThis.testClass = new Student('Davi', 1); 71 72globalThis.arrayTest = new Array(33); 73 74 75