> - strings are already interned in current engines for symbol-like 
> performance; there's no need to introduce symbols into the language

True.

> - private names are overkill for most uses of enums; just use string literals
> 
> - in SpiderMonkey I think you get better performance if your switch cases use 
> known constants; for example:
> 
>    const RED = "red", GREEN = "green", BLUE = "blue";
>    ...
>    switch (color) {
>      case RED: ...
>      case GREEN: ...
>      case BLUE: ...
>    }


What makes Allen’s pattern appealing is that an enum becomes a set of symbols. 
You then can look up your options and enumerate the set members. You don’t have 
a flat set of symbols, either, you have sets of related symbols.

Are you saying that comparing interned strings is faster than comparing two 
objects (supposedly by comparing their object IDs)? If so, Enum() could be 
adapted to:

function Enum() {
     let e =  {};
    Array.prototype.forEach.call(arguments,
        function(name) {
            e[name] = name;
        });
    return Object.freeze(e);
}


-- 
Dr. Axel Rauschmayer

[email protected]
twitter.com/rauschma

home: rauschma.de
blog: 2ality.com



_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to