Skip to content

Instantly share code, notes, and snippets.

@Randy808
Created September 27, 2020 22:25
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 Randy808/29f0058fd418d1246eb3e55553704157 to your computer and use it in GitHub Desktop.
Save Randy808/29f0058fd418d1246eb3e55553704157 to your computer and use it in GitHub Desktop.
Toy hook example for medium article.
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