Also only works when you're switching on something with a meaningful
conversion to string.



On 21 February 2014 07:03, Mathias Bynens <mathi...@opera.com> wrote:

> On 20 Feb 2014, at 21:20, Eric Elliott <e...@ericleads.com> wrote:
>
> > Object literals are already a great alternative to switch in JS:
> >
> > var cases = {
> >   val1:  function () {},
> >   val2: function () {}
> > };
> >
> > cases[val]();
>
> In that case, you’d need a `hasOwnProperty` check to make sure you’re not
> trying to call `__proto__` or `toString`, etc. See <
> https://github.com/rwaldron/idiomatic.js/#misc> for a more complete
> example.
>
> _______________________________________________
> es-discuss mailing list
> es-discuss@mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
>
_______________________________________________
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to