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
Perhaps you will at least find it interesting. :)
Nathan
From: cau.giacomo...@tiscali.it
To: es-discuss@mozilla.org
Subject: Another switch
Date: Sun, 9 Feb 2014 10:41:40 +0100
Hello to all
I wish to submit a little proposal.
Today the switch
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
: Another switch
Date: Sun, 9 Feb 2014 10:41:40 +0100
Hello to all
I wish to submit a little proposal.
Today the switch statement has an
explicit break at the end of the statement and an
implicit continue to the next case
but this break is very boring and error prone.
Wouldn’t
Hello to all
I wish to submit a little proposal.
Today the switch statement has an
explicit break at the end of the statement and an
implicit continue to the next case
but this break is very boring and error prone.
Wouldn’t it be possible to think a switch that has an
explicit
I'm new too, but don't think that's exactly how things get proposed here :)
Spec changes don't start with solutions - they start with existing problems
you're trying to solve. For example. In ES6 I might do
```js
var res = ({
hello : () = 12, /* no fallback */
world : () = 323, /* no
12 matches
Mail list logo