简体   繁体   中英

How to properly call a class method from within another method

Let's say I have the following class:

class MyClass {
    constructor () { /* etc */ }
    myFunc () {
        return myFuncToCall()
    }
    myFuncToCall () { /* etc */ }
}

What is the correct way to call myFuncToCall from within myFunc ?

the class syntax is just a syntax suger for prototype inheritence. every instance method is on the prototype of MyClass.

class MyClass {
     constructor() {

     }
     myFunc(){
       return this.myFuncToCall()
     }

     myFuncToCall(){

     }
   }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM