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?
2
Answers
I think the answer may be as simple as including the
#
when you call the method, as inthis.#myPrivateMethod()
. The docs for this are here.It works as the following example: