Skip to content

Instantly share code, notes, and snippets.

@nola
Created November 26, 2013 02:04
Show Gist options
  • Select an option

  • Save nola/7652406 to your computer and use it in GitHub Desktop.

Select an option

Save nola/7652406 to your computer and use it in GitHub Desktop.
switch shorthand
switch (something) {
case 1:
doX();
break;
case 2:
doY();
break;
case 3:
doN();
break;
// And so on...
}
//switch
var cases = {
1: doX,
2: doY,
3: doN
};
if (cases[something]) {
cases[something]();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment