3 ms·
Show HN: Enums in JavaScript, exploration of syntax hacking
- graderjs 5y agoHi Humans of HN, This is a little experiment in syntax hacking to try to get "Enums" in JavaScript. I'm quite happy with the first one, besides the first character of each value being silent but necessary in the definition (but not in the usage). Second one is workable, but less syntactically semantic. This just comes out a bit of exploration I was thinking of tonight about how to get enums in JavaScript. Thinking about C or Java flavored enums, but it would be possible to extend (the first one, anyway) to give go-flavored enumerator functions to customize the assigned numeric values for the constants. This is the only comment I'll make in this thread. I hope you enjoy. I'm sharing it as way to maybe give you ideas, bonce off something about syntax for you. :) ;p xx