title: Map of functions in javascript?
body: <p>I have a context menu that will trigger different javascript functions.
  The naive solution for choosing function looks like this:</p>
  
  <pre><code>function(action, el, pos) {
      switch(action)
      {
          case "export_selected_to_excel":
              exportSelectedToExcel(el);
              break;
  
          etc..
      }
  }
  </code></pre>
  
  <p>I would like to have a map of functions instead, so that I can reduce the metod to something similar to this:</p>
  
  <pre><code>function(action, el, pos) {
      menuAction[action](el);
  }
  </code></pre>
  
  <p>I define the array like this:</p>
  
  <pre><code>function exportSelectedToExcel(id){
     //stuff...
  }
  
  var menuAction = new Array();
  menuAction["export_selected_to_excel"] = exportSelectedToExcel;
  </code></pre>
  
  <p>This seems to work fine and feels like a reasonable solution.</p>
  
  <p>Are there any downsides to do like this in javascript?<br>
  Is there even better ways to do it?</p>