Re: Another switch

2014-02-21 Thread Nick Krempel
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:

Re: Another switch

2014-02-21 Thread Rick Waldron
On Fri, Feb 21, 2014 at 7:55 AM, Nick Krempel ndkrem...@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 e...@ericleads.com wrote: Object literals are already a great alternative to switch in

Re: Another switch

2014-02-21 Thread Eric Elliott
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

Re: Another switch

2014-02-21 Thread C. Scott Ananian
In the ES6 world, you should probably set up a Map for your switch statement; that would allow you to easily use non-string cases. --scott ___ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss

Re: Another switch

2014-02-20 Thread Eric Elliott
- From: Brendan Eich Sent: Wednesday, February 12, 2014 2:00 AM To: Nathan Wall Cc: Giacomo Cau ; es-discuss@mozilla.org Subject: Re: Another switch Definitely good to see new languages being designed and implemented. JS is not going to break compatibility on the old fall-through behavior

Re: Another switch

2014-02-20 Thread Mathias Bynens
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

Re: Another switch

2014-02-17 Thread Giacomo Cau
-Messaggio originale- From: Brendan Eich Sent: Wednesday, February 12, 2014 2:00 AM To: Nathan Wall Cc: Giacomo Cau ; es-discuss@mozilla.org Subject: Re: Another switch Definitely good to see new languages being designed and implemented. JS is not going to break compatibility

RE: Another switch

2014-02-11 Thread Nathan Wall
Hi Giacomo, Not sure whether this will be of interest to you, but I have been working on a JS-derived language called Proto (still highly experimental) which has a switch statement that works exactly as you described: https://github.com/Nathan-Wall/proto/blob/master/docs/control/switch.md

Re: Another switch

2014-02-11 Thread Brendan Eich
Definitely good to see new languages being designed and implemented. JS is not going to break compatibility on the old fall-through behavior of switch, inherited from Java from C++ from C. All the C-like languages copy this flaw, because to do otherwise with the same keyword would be worse

Re: Another switch

2014-02-11 Thread Claude Pache
Hi Nathan, Since the `switch/case` construct in Proto runs differently from the usual way, it should be spelt differently to avoid the confusion that will inevitably occur when switching between languages. For instance, Perl names it `given/when` [1], and SQL uses `case/when`. —Claude [1]