Created
June 9, 2020 14:57
-
-
Save wickkidd/e6b005132349ff7664e2b3af8abe9718 to your computer and use it in GitHub Desktop.
js get object properties (incl inherited)
This file contains hidden or 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
const getMethods = (obj) => { | |
let properties = new Set() | |
let currentObj = obj | |
do { | |
Object.getOwnPropertyNames(currentObj).map(item => properties.add(item)) | |
} while ((currentObj = Object.getPrototypeOf(currentObj))) | |
return [...properties.keys()].filter(item => typeof obj[item] === 'function') | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment