Skip to content

Instantly share code, notes, and snippets.

@idettman
Created October 16, 2015 18:49
Show Gist options
  • Save idettman/0a15681863d1d4b80bff to your computer and use it in GitHub Desktop.
Save idettman/0a15681863d1d4b80bff to your computer and use it in GitHub Desktop.
var Executor = (function()
{
var commands = {},
executor = {
handle: function(commandName, callback)
{
var commandHandler = {
ref: this,
callback: callback
};
commands[commandName] = commandHandler;
}
};
executor.handle = function(commandName, callback)
{
var commandHandler = {
ref: this,
callback: callback
};
commands[commandName] = commandHandler;
};
executor.execute = function(commandName, data)
{
var cmd = commands[commandName];
if (cmd)
{
cmd.callback.call(cmd.ref, data);
}
};
return executor;
})();
(function(Executor, context)
{
var showText = function(data)
{
console.log("Output text: " + data);
};
Executor.handle("consoleOut", showText);
})(Executor, this);
Executor.execute("consoleOut", "foobar");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment