TheM00s3
TheM00s3

Reputation: 3711

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?

Upvotes: 1

Views: 120

Answers (1)

Sean
Sean

Reputation: 3042

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(){

     }
   }

Upvotes: 5

Related Questions