Is there a way to retrieve an array of all functions from a given class, including functions inherited from parent classes?
For instance:
class Foo extends Bar {
funcA() {}
}
class Bar {
funcB() {}
}
const instanceFoo = new Foo();
getClassFunctions(instanceFoo); // should return an array ['funcA', 'funcB'];
I've created a function that fetches the names of a class's functions, but it only works for properties belonging directly to the class.
const getAllFuncs = (obj) => {
const proto = Object.getPrototypeOf(obj);
const names = Object.getOwnPropertyNames(proto);
return names.filter(name => typeof obj[name] === 'function' && name !== 'constructor');
}