Given an ES6 class, how can I inspect it to determine its gettable static properties and methods?
In ES5 determining the statics attached to a class (it\'s construct
If you want to get a dynamic list of standard class property names (so that you can filter them out of your list of static members), you can simply get the property names from an empty class:
const standardClassProps = Object.getOwnPropertyNames(class _{});
// ["length", "prototype", "name"]
This will produce a reasonably future-proof array that will dynamically adapt to changes to the standard, especially the addition of new standard static properties.
class Foo {
static bar() {}
}
function isOwnStaticMember(propName) {
return !standardClassProps.includes(propName);
}
const staticMembers = Object.getOwnPropertyNames( Foo ).filter(isOwnStaticMember);
// ["bar"]