Function Maps in JavaScript

var map = {
  functionOne: function(obj) {
    return'I am at functionOne: %o', obj);
  functionTwo: function(obj) {
    return'I am at functionTwo: %o', obj);
  functionThree: function(obj) {
    return'I am at functionThree: %o', obj);

C like function map which can then be used like map.functionOne({foo: 'bar'}).

I prefer to use objects like these instead of more typical control flow statements like if/else or switch. The map object can be called like map[key]({hello: 'World'}) , where key is the string.

Suppose you’re getting a data array of objects from some request, I can very neatly check all the items using something like this:

var arr ={
    return item[map[key](item)];