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