Created
November 26, 2013 02:04
-
-
Save nola/7652406 to your computer and use it in GitHub Desktop.
switch shorthand
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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