Skip to content

Instantly share code, notes, and snippets.

@vendethiel
Forked from jedahu/enum_example.js
Created January 3, 2014 00:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vendethiel/8230455 to your computer and use it in GitHub Desktop.
Save vendethiel/8230455 to your computer and use it in GitHub Desktop.
macro to_string {
case $x => { (JSON.stringify({ $x: 0 }).slice(2, -4)) }
}
macro enum {
case [ $val:ident (,) ... ] => {
(function () {
var e = {
$( $val : (to_string $val) ) (,) ...
};
Object.freeze(e);
return e;
})()
}
}
console.dir(enum [ Hallo, World ]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment