Skip to content

Instantly share code, notes, and snippets.

@batazo
Created July 9, 2022 21:15
Show Gist options
  • Save batazo/d0c5e801ab02e439581b748a716a42c4 to your computer and use it in GitHub Desktop.
Save batazo/d0c5e801ab02e439581b748a716a42c4 to your computer and use it in GitHub Desktop.
ENUM CREATOR
function createEnum(values) {
const enumObject = {};
for (const val of values) {
enumObject[val] = val;
}
return Object.freeze(enumObject);
}
// { Up: 'Up', Down: 'Down', Left: 'Left', Right: 'Right' }
const enums = createEnum(['Up', 'Down', 'Left', 'Right']);
console.log(enums)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment