Eric Elliott (2014-02-21T18:47:40.000Z)
In practice, I find that everything converts nicely to a string when you
precede it with a ternary assignment.

I also find that when you do that, it's pretty trivial to control what
those strings are, which makes `hasOwnProperty` superfluous.

I haven't used a switch in JavaScript for quite a few years now, and I
don't miss it at all.

- Eric

Author, "Programming JavaScript Applications" (O'Reilly)
http://ericleads.com/


On Fri, Feb 21, 2014 at 10:26 AM, Rick Waldron <waldron.rick at gmail.com>wrote:

>
>
>
> On Fri, Feb 21, 2014 at 7:55 AM, Nick Krempel <ndkrempel at google.com>wrote:
>
>> Also only works when you're switching on something with a meaningful
>> conversion to string.
>>
>
> On 20 Feb 2014, at 21:20, Eric Elliott <eric at ericleads.com> wrote:
>
> > Object literals are already a great alternative to switch in JS:
> >
> > var cases = {
> >   val1:  function () {},
> >   val2: function () {}
> > };
> >
> > cases[val]();
>
>
> Right, this wouldn't work if the "case" wanted object references, but it
> would work nicely with Symbols.
>
> Rick
>
>
> _______________________________________________
> 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/20140221/e9dcf070/attachment.html>
domenic at domenicdenicola.com (2014-02-24T21:28:26.547Z)
In practice, I find that everything converts nicely to a string when you
precede it with a ternary assignment.

I also find that when you do that, it's pretty trivial to control what
those strings are, which makes `hasOwnProperty` superfluous.

I haven't used a switch in JavaScript for quite a few years now, and I
don't miss it at all.