Created
October 25, 2016 23:17
-
-
Save GMali/8407793edd602474cca8f71ba6099337 to your computer and use it in GitHub Desktop.
Accessing ES6 getters
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
// For question: http://stackoverflow.com/questions/40249605/how-do-i-get-the-result-of-class-getters-into-json | |
function getMethodNames(obj) { | |
return Object.getOwnPropertyNames(obj.constructor.prototype); | |
} | |
function isGetter(obj, method) { | |
let desc = Object.getOwnPropertyDescriptor(obj.constructor.prototype, method); | |
return !!desc.get; | |
} | |
function getters(obj) { | |
return getMethodNames(obj).filter(method => isGetter(obj, method)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment