• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#  ``Function.apply``, ``Function.bind``, ``Function.call`` are not supported
2
3Rule ``arkts-no-func-apply-bind-call``
4
5**Severity: error**
6
7ArkTS does not allow using standard library functions ``Function.apply``,
8``Function.bind`` and ``Function.call``. These APIs are needed in the standard
9library to explicitly set ``this`` parameter for the called function.
10In ArkTS the semantics of ``this`` is restricted to the conventional OOP
11style, and the usage of ``this`` in stand-alone functions is prohibited.
12Thus these functions are excessive.
13
14
15## TypeScript
16
17
18```
19
20    const person = {
21        firstName: "aa",
22
23        fullName: function(): string {
24            return this.firstName
25        }
26    }
27
28    const person1 = {
29        firstName: "Mary"
30    }
31
32    // This will log "Mary":
33    console.log(person.fullName.apply(person1))
34
35```
36
37## ArkTS
38
39
40```
41
42    class Person {
43        firstName : string
44
45        constructor(firstName : string) {
46            this.firstName = firstName
47        }
48        fullName() : string {
49            return this.firstName
50        }
51    }
52
53    let person = new Person("")
54    let person1 = new Person("Mary")
55
56    // This will log "Mary":
57    console.log(person1.fullName())
58
59```
60
61## See also
62
63- Recipe 093:  Using ``this`` inside stand-alone functions is not supported (``arkts-no-standalone-this``)
64
65
66