I was playing around with the concept of enums / constants in coffeescript ( http://coffeescript.org/ ) and came up with the following code below which seems OK. How can I enhance this to be even better for something where an enum would fit? google searches for this have not yet revealed satisfaction.
class SomeService
@SomeEnumValue : 400
@SomeOtherValue : 402
someFunc: ->
SomeService.SomeEnumValue
ok = new SomeService()
alert ok.someFunc()
if (ok.someFunc() == SomeService.SomeEnumValue) then alert ' some enum value'
The whole concept of enum is just useless in dynamic languages as is tuple, typed list, map and lots of other stuff, and Javascript (Coffeescript) is dynamic. While working with dynamic language you just have to forget about type checking and use the existing more general constructs to solve your problem. Use arrays instead of lists and tuples, use objects instead of maps and enums and just trust the type of value passed to the function, but heavily unit-test your code. For better or worse (for worse IMO) that’s just how a work is done here.
In your case I would recommend just storing your values in a singleton object, like so:
and accessing it like so: