Skip to content

Instantly share code, notes, and snippets.

@andrienko
Created March 17, 2014 15:15
Show Gist options
  • Save andrienko/9601121 to your computer and use it in GitHub Desktop.
Save andrienko/9601121 to your computer and use it in GitHub Desktop.
document.registerCallback = function(callbackEvent, callbackFunction){
if(typeof document.callbacks == 'undefined')document.callbacks = {};
if(typeof document.callbacks[callbackEvent]=='undefined')document.callbacks[callbackEvent]=[];
document.callbacks[callbackEvent].push(callbackFunction);
return callbackFunction;
};
document.runCallbacks = function(callbackEvent,arguments){
for(var name in document.callbacks[callbackEvent]){
document.callbacks[callbackEvent][name].apply(null,arguments);
}
}
@andrienko
Copy link
Author

А потом я такой:

document.registerCallback("pageLoad",function(firstword){console.log(firstword + ', world!');});

И такой типа, где-то глубоко в коде

document.runCallbacks('pageLoad',["Hello"]);

..и даже параметры передаются.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment