es-discuss Digest, Vol 106, Issue 46

John Gardner gardnerjohng at gmail.com
Wed Dec 16 12:14:04 UTC 2015


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.


On 16 December 2015 at 23:00, <es-discuss-request at mozilla.org> wrote:

> Send es-discuss mailing list submissions to
>         es-discuss at mozilla.org
>
> To subscribe or unsubscribe via the World Wide Web, visit
>         https://mail.mozilla.org/listinfo/es-discuss
> or, via email, send a message with subject or body 'help' to
>         es-discuss-request at mozilla.org
>
> You can reach the person managing the list at
>         es-discuss-owner at mozilla.org
>
> When replying, please edit your Subject line so it is more specific
> than "Re: Contents of es-discuss digest..."
>
> Today's Topics:
>
>    1. Re: Propose simpler string constant (Coroutines)
>
>
> ---------- Forwarded message ----------
> From: Coroutines <coroutines at gmail.com>
> To: es-discuss <es-discuss at mozilla.org>
> Cc:
> Date: Wed, 16 Dec 2015 03:31:26 -0800
> Subject: Re: Propose simpler string constant
> On Wed, Dec 16, 2015 at 3:20 AM, Thomas <thomasjamesfoster at bigpond.com>
> wrote:
> > IMHO it'd be a huge mistake to not use symbols for enums.
> >
> > In my head this:
> >
> > const colours = enum {
> >   Red,
> >   Yellow,
> >   Green,
> >   Blue
> > }
> >
> > should 'desugar' to something like this in ES6:
> >
> > const colours = {
> >   Red: Symbol('Red'),
> >   Yellow: Symbol('Yellow'),
> >   Green: Symbol('Green'),
> >   Blue: Symbol('Blue')
> > }
> >
> > Thomas
>
> This person gets it. +1  :-)
>
>
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20151216/ef45bc86/attachment.html>


More information about the es-discuss mailing list