News for hackers. Stuff that matters.
Re:Using Dispatch Tables to Avoid Conditionals in JavaScript by Leszek on Monday May 13, 2013 @02:00PM (#5700268)
I don't know, in this case, with a bit of reformatting the switch can look pretty similar:

    function processUserInput(command) {
        switch (command) {
            case "north":    movePlayer("north"); break;
            case "east":     movePlayer("east");  break;
            case "south":    movePlayer("south"); break;
            case "west":     movePlayer("west");  break;
            case "look":     describeLocation();  break;
            case "backpack": showBackpack();      break;
        }
    }
Although that's to be expected, a switch on a string value isn't that much different to a string lookup in an associative array.
Re:Using Dispatch Tables to Avoid Conditionals in JavaScript by Tactic on Monday May 13, 2013 @04:08PM (#5701089)
Except with an array you can change things programmatically on the fly. Or have it setup in a configuration file or database table. Very useful.