Propose simpler string constant

kdex kdex at kdex.de
Wed Dec 16 12:44:49 UTC 2015


Yes, I'd favor the `Symbol()` approach a lot. @Andrea: Alternatively 
desugaring `enum` values to `Number` is probably an approach that leads 
back to C/C++'s `#define` (which turns out to be a disastrous idea, at 
least software-engineering-wise), since this has horrendous impacts on 
comparison. Consider this:

```js

const PIXELS = enum {
	RED,
	GREEN,
	BLUE
};
const VEGGIES = enum {
	ONION,
	TOMATO
	
};
assert(PIXELS.RED === 0);
assert(VEGGIES.ONION === 0);
// Oops
assert(PIXELS.RED === VEGGIES.ONION);

```

Alternatively choosing `String()` would suffer from the same issue, but 
only clash when two `enum`s share common value identifiers; so 
`Symbol()` really is the only reasonable thing to desugar to.


On 16.12.2015 12:31, Coroutines wrote:
> 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



More information about the es-discuss mailing list