Back
What is the preferred syntax for defining enums in JavaScript? Something like:
my.namespace.ColorEnum = {RED : 0, GREEN : 1, BLUE : 2 }// later on if(currentColor == my.namespace.ColorEnum.RED) { // whatever}
my.namespace.ColorEnum = {
RED : 0,
GREEN : 1,
BLUE : 2
}
// later on
if(currentColor == my.namespace.ColorEnum.RED) {
// whatever
Or is there a more preferable idiom?
var DaysEnum = Object.freeze({"monday":1, "tuesday":2, "wednesday":3, ...})
or
var DaysEnum = {"monday":1, "tuesday":2, "wednesday":3, ...} Object.freeze(DaysEnum)
31k questions
32.8k answers
501 comments
693 users