Created
August 26, 2015 23:26
-
-
Save alkhe/0edf693b92cb8e103ffc to your computer and use it in GitHub Desktop.
Reflect all prototype-inherited instance methods. (ES6 classes)
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
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