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 16import * as ns from '../../mod1' 17import { bar as bar2 } from './mod2' 18 19function func1(o1, o2) { } 20 21// call scope-defined function/global function 22function foo(o1, o2) { 23 let func2 = (x) => { return x * 2; } 24 func2(o2.x); 25 26 // call func from global variable 27 console.log("log"); 28 globalvar.hilog.logd("logd"); 29 30 let func3 = func2 31 let func4 = func3; 32 func4(o1.x); 33 34 let a = o1.x; 35 if (a) { 36 func1(2, o2.y); 37 o2.bar(); 38 } 39} 40 41// indirect call via 'apply' or 'call' 42function foo1(o1, o2, o3) { 43 let obj = { z: 2 }; 44 function fn(x, y) { 45 print(x + y + this.z); 46 } 47 48 fn.call(obj, 2, 3); 49 fn.apply(obj, [2, 3]); 50 let bound = fn.bind(obj, 4); 51} 52 53class Point { 54 constructor(x, y) { 55 this.x = x; 56 this.y = y; 57 } 58 59 get getCoordinateX() { 60 return this.x; 61 } 62 63 set setCoordinateX(x) { 64 return this.x = x; 65 } 66 67 plus(other) { 68 this.x += other.x; 69 this.y += other.y; 70 } 71 72} 73 74function func5() { 75 // call super 76 class ColorPoint extends Point { 77 constructor(x, y, color) { 78 super(x, y); 79 this.color = color; 80 } 81 } 82} 83 84// call function of across module 85function func6(o1, o2) { 86 bar2(); 87 88 function func7() { 89 var func8 = ns.math.sum; 90 func8(1, 2); 91 ns.sub(o2, o1); 92 } 93} 94 95// call member function 96function func9() { 97 let point = new Point(2, 3); 98 99 function callMemberFunc1(p) { 100 let x = point.getCoordinateX(); 101 point.setCoordinateX(x); 102 let point2 = point 103 104 function callMemberFunc2(p) { 105 point2.plus(p); 106 point2.sub(p); 107 } 108 } 109} 110 111function func10(o1, o2) { 112 let service = new ns.PhoneService(); 113 function callExClassMemberFunc1(o) { 114 service.makePhoneCall(o); 115 } 116} 117