Created
January 22, 2014 00:25
-
-
Save jugglinmike/8551293 to your computer and use it in GitHub Desktop.
suite.js: `nin` operator macro
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
// Use suite.js to define a JavaScript macro for a "not in" operator | |
// http://sweetjs.org/ | |
macro nin { | |
rule infix { | |
$key:expr | $obj:expr | |
} => { | |
!($key in $obj) | |
} | |
} | |
// Now, | |
if (key nin obj) { | |
return null; | |
} | |
// ...compiles to: | |
if (!(key in obj)) { | |
return null; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment