Last active
December 26, 2015 10:29
-
-
Save jsonnull/7137077 to your computer and use it in GitHub Desktop.
Just a simple hack I came up with to facilitate really short pattern-matching. It is effectively a chain of if-elseif statements. The first time a condition is true, the associated expression or code block is evaluated, and nothing further.
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
var x = false, | |
y = true; | |
// Call functions in the evaluation | |
(x && y)? alert("x and y matched") | |
: x? alert("x matched") | |
: y? alert("y matched") | |
: alert("default") | |
// Just do an assignment | |
var output = | |
(x && y)? "x and y" | |
: x? "x" | |
: y? "y" | |
: "none" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment