It looks like you are describing the / case switch, but I don't think the switch case is better than a few if / else structures. I prefer to use hashes of objects:
var actionObj = {
"Edit": xx,
"Create": xy,
"Delete": xz
};
if (actionObj[act]) {
} else {
}
This works especially well when values are actually functions, then you can just call them:
var actionObj = {
"Edit": function () {},
"Create": function () {},
"Delete": function () {}
};
if (actionObj[act]) {
actionObj[act]();
} else {
}
source
share