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