You can use destructuring assignment to define enumerations in ES6 as follows:
var [red, green, blue] = [0, 1, 2];
Instead, I'd like the right hand side of the destructuring assignment to be dynamic. For example:
var MAX_ENUM_SIZE = 32;
var ENUM = new Array(MAX_ENUM_SIZE);
for (var i = 0; i < MAX_ENUM_SIZE; i++) ENUM[i] = i;
var [red, green, blue] = ENUM;
Unfortunately, this seems like a hack. What if I want a bigger enumeration in the future? Hence, I was thinking of using destructuring assignment with an iterator as follows:
var [red, green, blue] = enumeration(/* I don't want to specify size */);
However, I don't think it's possible to use destructuring assignment with iterators[citation needed]. Is there any way to accomplish this goal?