Last active
October 25, 2016 05:10
-
-
Save yakovkhalinsky/7223990 to your computer and use it in GitHub Desktop.
Possible implementation of Enums in Coffeescript
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
class Enum | |
constructor: (fields) -> | |
if !fields?.length or !Array.isArray fields then throw 'Fields must be an array of Strings' | |
fields.forEach (field) => @[field.toUpperCase()] = field.toUpperCase() | |
myEnum = new Enum(['ONE', 'TWO']) | |
console.log 'Enum', myEnum |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment