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:
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
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
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
-
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
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
-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
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
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
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]
10 matches
Mail list logo