My class has a method whose name is a string. But it seems not enumerable! Even Object.getOwnPropertyNames
doesn't work. So, how do I get the method name/key?
class MyClass {
'hello/world'() {
console.log("You just called 'hello/world'");
}
}
const my = new MyClass();
// For in loop
let keys = [];
for (let key in my) {
keys.push(key);
}
console.log('For in loop: ' + keys);
// Object.getOwnPropertyNames
console.log('Object.getOwnPropertyNames: ' + Object.getOwnPropertyNames(my));
// Call the method
my['hello/world']();