Skip to content

Instantly share code, notes, and snippets.

@jaz303
Last active January 19, 2023 04:46
Show Gist options
  • Save jaz303/412c30af73720406366e20d536c899ce to your computer and use it in GitHub Desktop.
Save jaz303/412c30af73720406366e20d536c899ce to your computer and use it in GitHub Desktop.
Concise enums via ES6 destructuring
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