Last active
August 29, 2015 14:14
-
-
Save gr0uch/d8d8d6892bb693c9ac39 to your computer and use it in GitHub Desktop.
Enumerate class methods
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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