Skip to content

Instantly share code, notes, and snippets.

@andrienko
Created Mar 17, 2014
Embed
What would you like to do?
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

This comment has been minimized.

Copy link
Owner Author

@andrienko andrienko commented Mar 17, 2014

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

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