Last active
March 9, 2016 22:40
-
-
Save vladimir-ivanov/eaa4549481e8f7118795 to your computer and use it in GitHub Desktop.
ECMA6 Class get all methods from all inherited classes
This file contains hidden or 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
function getClassMethods(className) { | |
if (!className instanceof Object) { | |
throw new Error("Not a class"); | |
} | |
let ret = new Set(); | |
function methods(obj) { | |
if (obj) { | |
let ps = Object.getOwnPropertyNames(obj); | |
ps.forEach(p => { | |
if (obj[p] instanceof Function) { | |
ret.add(p); | |
} else { | |
//can add properties if needed | |
} | |
}); | |
methods(Object.getPrototypeOf(obj)); | |
} | |
} | |
methods(className.prototype); | |
return Array.from(ret); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment