Skip to content

Instantly share code, notes, and snippets.

@yakovkhalinsky
Last active October 25, 2016 05:10
Show Gist options
  • Save yakovkhalinsky/7223990 to your computer and use it in GitHub Desktop.
Save yakovkhalinsky/7223990 to your computer and use it in GitHub Desktop.
Possible implementation of Enums in Coffeescript
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