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 <[email protected]>wrote:

>
>
>
> On Fri, Feb 21, 2014 at 7:55 AM, Nick Krempel <[email protected]>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 <[email protected]> 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
> [email protected]
> https://mail.mozilla.org/listinfo/es-discuss
>
>
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to