Skip to content

Instantly share code, notes, and snippets.

@vladimir-ivanov
Last active March 9, 2016 22:40
Show Gist options
  • Save vladimir-ivanov/eaa4549481e8f7118795 to your computer and use it in GitHub Desktop.
Save vladimir-ivanov/eaa4549481e8f7118795 to your computer and use it in GitHub Desktop.
ECMA6 Class get all methods from all inherited classes
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