How can I call a private method from a public method in javascript?

  Kiến thức lập trình
class myClass
{
   myPublicMethod(e)
   {
      console.log(this);
      myPrivateMethod(); //does not work
   }

   #myPrivateMethod()
   {
      console.log('in myPrivateMethod');
   }
}

I’ve confirmed that this is myClass via console.log. I get the error myPrivateMethod is not defined. If I try this.myPrivateMethod(); then I get the error myPrivateMethod is not a function. The only thing that works is removing the # from myPrivateMethod making it public and calling it via this.my(formerly)PrivateMethod();

Is it possible to call this function while keeping it private?

LEAVE A COMMENT