Last active
January 19, 2023 04:46
-
-
Save jaz303/412c30af73720406366e20d536c899ce to your computer and use it in GitHub Desktop.
Concise enums via ES6 destructuring
This file contains 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
function enumeration() { | |
const out = []; | |
for (let ix = 0; ix < arguments.length; ++ix) { | |
let val = {}; | |
Object.defineProperty(val, 'name', { | |
value: arguments[ix], | |
writable: false, | |
configurable: false | |
}); | |
out.push(val); | |
} | |
return out; | |
} | |
const [UNKNOWN, READY, RUNNING] = enumeration('UNKNOWN', 'READY', 'RUNNING'); | |
let state = UNKNOWN; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment