JavaScript - Method Lookup / Lookup Table / Dispatch Table
// FROM: http://us5.campaign-archive2.com/?u=ea228d7061e8bbfa8639666ad&id=be8ff9ee56&e=ff0570c0b6
function doSomething (condition) {
var stuff = {
'one': function () {
return 'one';
},
'two': function () {
return 'two';
},
'three': function () {
return 'three';
}
};
if (typeof stuff[condition] !== 'function') {
return 'default';
}
return stuff[condition]();
}