Last active
January 11, 2019 12:17
-
-
Save rxluz/d5f90c8aca8b44d083b519c35f5b90c0 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
//enum is a reserved word in new ES6 reserved words list, that's the reason the method call ENUM_ | |
class Enum_ { | |
constructor(...list) { | |
const objList = list.reduce((acummulator, value) => { | |
acummulator[value] = Symbol(value); | |
return acummulator; | |
}, {}); | |
return Object.freeze(objList); | |
} | |
} | |
//usage examples | |
const COLORS = new Enum_("RED", "GREEN", "BLUE"); | |
const SIZE = new Enum_("SMALL", "MEDIUM", "LARGE", "HUGE"); | |
const STATUS = new Enum_("SOLD", "AVAILABLE"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment