Created
October 16, 2015 18:49
-
-
Save idettman/0a15681863d1d4b80bff to your computer and use it in GitHub Desktop.
This file contains 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
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