Skip to content

Instantly share code, notes, and snippets.

@rxluz
Last active January 11, 2019 12:17
Show Gist options
  • Save rxluz/d5f90c8aca8b44d083b519c35f5b90c0 to your computer and use it in GitHub Desktop.
Save rxluz/d5f90c8aca8b44d083b519c35f5b90c0 to your computer and use it in GitHub Desktop.
//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