Created
June 11, 2014 05:07
-
-
Save twitchy/26f6415d90ae6ec19fe3 to your computer and use it in GitHub Desktop.
Dispatch Tables
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 thingsWeCanDo = { | |
doThisThing : function() { /* behavior */ }, | |
doThatThing : function() { /* behavior */ }, | |
doThisOtherThing : function() { /* behavior */ }, | |
default : function() { /* behavior */ } | |
}; | |
var doSomething = function(doWhat) { | |
var thingToDo = thingsWeCanDo.hasOwnProperty(doWhat) ? doWhat : "default" | |
thingsWeCanDo[thingToDo](); | |
} | |
var commandTable = { | |
north: function() { console.log("north"); }, | |
east: function() { console.log("east"); }, | |
south: function() { console.log("south"); }, | |
west: function() { console.log("west"); }, | |
} | |
function testDispatchTable(command) { | |
commandTable[command](); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment