13af6ab5fSopenharmony_ci#  ``Function.bind`` is not supported
23af6ab5fSopenharmony_ci
33af6ab5fSopenharmony_ciRule ``arkts-no-func-bind``
43af6ab5fSopenharmony_ci
53af6ab5fSopenharmony_ci**Severity: warning**
63af6ab5fSopenharmony_ci
73af6ab5fSopenharmony_ciArkTS does not allow using standard library function ``Function.bind``.
83af6ab5fSopenharmony_ciThis API is needed in the standard library to explicitly set ``this``
93af6ab5fSopenharmony_ciparameter for the called function.
103af6ab5fSopenharmony_ciIn ArkTS the semantics of ``this`` is restricted to the conventional OOP
113af6ab5fSopenharmony_cistyle, and the usage of ``this`` in stand-alone functions is prohibited.
123af6ab5fSopenharmony_ciThus this function is excessive.
133af6ab5fSopenharmony_ci
143af6ab5fSopenharmony_ci
153af6ab5fSopenharmony_ci## TypeScript
163af6ab5fSopenharmony_ci
173af6ab5fSopenharmony_ci
183af6ab5fSopenharmony_ci```
193af6ab5fSopenharmony_ci
203af6ab5fSopenharmony_ci    const person = {
213af6ab5fSopenharmony_ci        firstName: "aa",
223af6ab5fSopenharmony_ci
233af6ab5fSopenharmony_ci        fullName: function(): string {
243af6ab5fSopenharmony_ci            return this.firstName
253af6ab5fSopenharmony_ci        }
263af6ab5fSopenharmony_ci    }
273af6ab5fSopenharmony_ci
283af6ab5fSopenharmony_ci    const person1 = {
293af6ab5fSopenharmony_ci        firstName: "Mary"
303af6ab5fSopenharmony_ci    }
313af6ab5fSopenharmony_ci
323af6ab5fSopenharmony_ci    // This will log "Mary":
333af6ab5fSopenharmony_ci    const boundFullName = person.fullName.bind(person1)
343af6ab5fSopenharmony_ci    console.log(boundFullName())
353af6ab5fSopenharmony_ci
363af6ab5fSopenharmony_ci```
373af6ab5fSopenharmony_ci
383af6ab5fSopenharmony_ci## ArkTS
393af6ab5fSopenharmony_ci
403af6ab5fSopenharmony_ci
413af6ab5fSopenharmony_ci```
423af6ab5fSopenharmony_ci
433af6ab5fSopenharmony_ci    class Person {
443af6ab5fSopenharmony_ci        firstName : string
453af6ab5fSopenharmony_ci
463af6ab5fSopenharmony_ci        constructor(firstName : string) {
473af6ab5fSopenharmony_ci            this.firstName = firstName
483af6ab5fSopenharmony_ci        }
493af6ab5fSopenharmony_ci        fullName() : string {
503af6ab5fSopenharmony_ci            return this.firstName
513af6ab5fSopenharmony_ci        }
523af6ab5fSopenharmony_ci    }
533af6ab5fSopenharmony_ci
543af6ab5fSopenharmony_ci    let person = new Person("")
553af6ab5fSopenharmony_ci    let person1 = new Person("Mary")
563af6ab5fSopenharmony_ci
573af6ab5fSopenharmony_ci    // This will log "Mary":
583af6ab5fSopenharmony_ci    console.log(person1.fullName())
593af6ab5fSopenharmony_ci
603af6ab5fSopenharmony_ci```
613af6ab5fSopenharmony_ci
623af6ab5fSopenharmony_ci## See also
633af6ab5fSopenharmony_ci
643af6ab5fSopenharmony_ci- Recipe 093:  Using ``this`` inside stand-alone functions is not supported (``arkts-no-standalone-this``)
653af6ab5fSopenharmony_ci
663af6ab5fSopenharmony_ci
67