Skip to content

Instantly share code, notes, and snippets.

@Sprit3Dan
Created April 23, 2020 04:55
Show Gist options
  • Select an option

  • Save Sprit3Dan/01dc4d892d9b97b7422cba7535c39f9f to your computer and use it in GitHub Desktop.

Select an option

Save Sprit3Dan/01dc4d892d9b97b7422cba7535c39f9f to your computer and use it in GitHub Desktop.
getEnum = function(values) {
var obj = {};
values.forEach((v, iter) => {
Object.defineProperty(obj, v, {
enumerable: true,
get() {
return v
}
});
});
Object.freeze(obj)
return obj;
}
const months = getEnum(["Jan", "Feb", "Mar"])
console.log(months);
console.log(months.Jan);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment