es-discuss Digest, Vol 106, Issue 46

Coroutines coroutines at gmail.com
Wed Dec 16 13:12:54 UTC 2015


On Wed, Dec 16, 2015 at 4:14 AM, John Gardner <gardnerjohng at gmail.com> wrote:
> I do fully agree with the notion that enums should generate Symbols by
> default... however, it seems unreasonable to prevent users from assigning
> other types as well.
>
> Should enums also offer programmers the ability to assign explicit values,
> as per traditional enum constructs? For instance, in TypeScript, coders are
> able to assign values manually, or even elevate the initial index that
> enumerations are counted from:
>
> const colours = {
>     Red = 1,
>     Green, //  2
>     Blue  // 3
> };
>
> We can probably do away with the initial index elevation (since enum'd names
> would default to the Symbol representation of the identifier, anyway), but I
> imagine many developers would expect to be able to assign integers in JS
> enums the same way they can in C, et al.

`enum` is probably the wrong keyword for the problem we're trying to
solve by desugaring unique identifier declarations to Symbol creation.
We're defining constants that should have no relation to each other.
We're not enumerating anything as it's supposed to be a 'secret'
Symbols are special globally defined integer identities behind the
scenes.

I'd personally add both?

```future-js-stuff
sym RED, GREEN, BLUE;  # const RED = Symbol('RED')', GREEN =
Symbol('GREEN'), BLUE = Symbol('BLUE');
enum { RED: = 5, GREEN, BLUE }; # const RED = 5, GREEN = 6, BLUE = 7;
```


More information about the es-discuss mailing list