Created
February 26, 2011 15:29
-
-
Save bxt/845303 to your computer and use it in GitHub Desktop.
Interesting method to do multi-value-testing in JS
This file contains 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
({abc:1,def:1,jkl:1}[xyz]) | |
// nearly the same as: | |
( xyz=="abc" || xyz=="def" || xyz=="jkl" ) | |
// and.... | |
(function(){switch(pn) { | |
case "prv":return "previous"; | |
case "nxt":return "next"; | |
}})() | |
// returns the same as: | |
(pn=="prv"?"previous":(pn=="nxt"?"next":undefined)) | |
// which returns the same as: | |
({"prv":"previous","nxt":"next"}[pn]) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment