Skip to content

Instantly share code, notes, and snippets.

@gr0uch
Last active August 29, 2015 14:14
Show Gist options
  • Save gr0uch/d8d8d6892bb693c9ac39 to your computer and use it in GitHub Desktop.
Save gr0uch/d8d8d6892bb693c9ac39 to your computer and use it in GitHub Desktop.
Enumerate class methods
/**
* Get a hash of a class's methods. This is not so straightforward
* because class methods are not enumerable.
*
* @param {Class} cls
* @return {Object}'
*/
export default function enumerateMethods (cls = class {}) {
return Object.getOwnPropertyNames(cls.prototype)
.reduce((methods, method) => {
methods[method] = cls.prototype[method];
return methods;
}, {});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment