Skip to content

Instantly share code, notes, and snippets.

@alkhe
Created August 26, 2015 23:26
Show Gist options
  • Save alkhe/0edf693b92cb8e103ffc to your computer and use it in GitHub Desktop.
Save alkhe/0edf693b92cb8e103ffc to your computer and use it in GitHub Desktop.
Reflect all prototype-inherited instance methods. (ES6 classes)
let writeMethods = (o, arr) => {
// skip constructor
for (let i = 1; i < arr.length; i++) {
o[arr[i]] = 0;
}
};
// Get object mirroring all instance methods of Class
export let methods = Class => {
let last = Object.__proto__;
let m = {};
do {
writeMethods(m, Object.getOwnPropertyNames(Class.prototype));
} while ((Class = Class.__proto__) !== last);
return m;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment