0

Given the following ES6 class:

class MyClass
{
    static static1() {}
    static get static2() {}
    get nonstatic() {}
}

...is there a way to loop through only the static methods/properties (including getters)?

sookie
  • 2,437
  • 3
  • 29
  • 48
  • 1
    How is this a duplicate of `ES6 Iterate over class methods`? – Keith Sep 18 '17 at 16:04
  • Looking at inspector for static methods, they don't get attached to the prototype, so doing -> `Object.getOwnPropertyNames( MyClass )` would get you the static methods, and `Object.getOwnPropertyNames( MyClass.prototype )` would get you the normal methods. – Keith Sep 18 '17 at 16:19
  • @Jonasw `MyClass[Symbol.iterator] is not a function` – Keith Sep 18 '17 at 16:24
  • @Jonasw I think methods as default are not enumerable, so this returns nothing.. :( – Keith Sep 18 '17 at 16:31
  • `Object.entries(Object.getOwnPropertyDescriptors(Api)).filter(([, {value}]) => typeof value === 'function').map(([prop]) => prop)` – Mir-Ismaili Feb 17 '22 at 21:12

0 Answers0