Skip to content

Instantly share code, notes, and snippets.

@banyudu
Created September 6, 2017 08:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save banyudu/4a5ac80acf6299192de50f81b9942365 to your computer and use it in GitHub Desktop.
Save banyudu/4a5ac80acf6299192de50f81b9942365 to your computer and use it in GitHub Desktop.
Get method names from class in javascript
class User {
constructor() {
// do nothing
}
*createUser(params) {
// TODO: implement this function
}
*getUser(params) {
// TODO: implement this function
}
*updateUser(params) {
// TODO: implement this function
}
*deleteUser(params) {
// TODO: implement this function
}
}
const attrs = Object.getOwnPropertyNames(User.prototype);
for (const attr of attrs) {
const blacklist = ['constructor'];
const type = typeof User.prototype[attr];
if (type === 'function') {
// do something
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment