JSFiddle - React, Tailwind, and code Playground
JavaScript
class MyClass {
#somePrivateMethod() {
return true;
}
somePublicMethod() {
return true;
}
existPrivateMethod(name) {
return typeof this[`#${name}`] === "function"; // not work
}
existPublicMethod(name) {
return typeof this[name] === "function";
}
}
let myClass = new MyClass();
console.log(
myClass.existPublicMethod('somePublicMethod'),
myClass.existPrivateMethod('somePrivateMethod')
);