Last active
July 22, 2020 06:23
-
-
Save yanai101/c6188e76003ee45edfa79eb8c03238e1 to your computer and use it in GitHub Desktop.
build dynamic ststic class methods
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
| 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