Created
September 27, 2020 22:25
-
-
Save Randy808/29f0058fd418d1246eb3e55553704157 to your computer and use it in GitHub Desktop.
Toy hook example for medium article.
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 Hook { | |
constructor(){ | |
this.hookedFunctions = []; | |
} | |
hookFunction(functionToHook){ | |
this.hookedFunctions.push(functionToHook); | |
} | |
callHook(){ | |
this.hookedFunctions.forEach(hookedFunction => hookedFunction()); | |
} | |
} | |
var hook = new Hook(); | |
hook.hookFunction(() => console.log("hello")) | |
hook.hookFunction(() => console.log("world")) | |
hook.callHook(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment