Skip to content

Instantly share code, notes, and snippets.

@yanai101
Last active July 22, 2020 06:23
Show Gist options
  • Save yanai101/c6188e76003ee45edfa79eb8c03238e1 to your computer and use it in GitHub Desktop.
Save yanai101/c6188e76003ee45edfa79eb8c03238e1 to your computer and use it in GitHub Desktop.
build dynamic ststic class methods
class DynamicMethods{
constructor(action){
for (const key in action) {
DynamicMethods[`${key}`] = new Function(`cb`, `${action[key]}`);
}
}
}
const action = {
onFoo : "console.log('foo')",
onBar : "console.log('BAR')"
}
const t = new DynamicMethods(action);
DynamicMethods.onFoo();
DynamicMethods.onBar();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment