Skip to content

Instantly share code, notes, and snippets.

@GMali
Created October 25, 2016 23:17
Show Gist options
  • Save GMali/8407793edd602474cca8f71ba6099337 to your computer and use it in GitHub Desktop.
Save GMali/8407793edd602474cca8f71ba6099337 to your computer and use it in GitHub Desktop.
Accessing ES6 getters
// 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