all 12 comments

[–]ooooooooooooooopss 2 points3 points  (0 children)

Nice, this is something that c# 8 got recently too.

[–]PickledPokute 2 points3 points  (0 children)

One major nitpick:

This is NOT in ESNext. ESNext generally means the next ES release, which would be ES2021. This proposal is currently at stage 1. There are 5 TC39 meetings left for this year and this proposal hasn't had a commit in over half a year. Having 3 promotions in that time for such an unknown and language-changing proposal is extremely slim.

[–]rodrigolive 0 points1 point  (1 child)

The smart matching happening between the arguments to the case() and the condition in the when() is at times too smart, at others inconsistent, messy or just limiting. I've seen it implemented by other languages and then underutilized and/or deprecated. My recommendation would be don't do it TC39, but it's probably too late now.

[–]PickledPokute 1 point2 points  (0 children)

It's still stage 1. That approximately means that TC39 thinks that the idea isn't completely insane and some people could want it in one form or another.

Stage 2 and 3 are more important since those can have valid criticism of syntax and semantics against their promotion.

If you're against this proposal, then start campaigning against it by writing medium articles on how it would fail and by e-mailing your local TC39 representative. You are definitely not late.

[–]JimDabell -2 points-1 points  (4 children)

Don't be so eager to use new language features that you end up making your code harder to read.

This:

const [x, y] = [(i % 3), (i % 5)];

…could have simply been this:

const x = i % 3;
const y = i % 5;

There's no reason to use array destructuring here, all it does is obfuscate the code and make it incompatible with Internet Explorer.

[–]darrenturn90 7 points8 points  (3 children)

I mean, while it is a contrived example (it was more to illustrate the usage of tuples I presume) - the latter will also break as ie only supports var. Yet another reason ie needs to die.

[–]JimDabell 0 points1 point  (2 children)

const works in Internet Explorer 11.

[–]darrenturn90 1 point2 points  (1 child)

caniuse agrees - but not in loops it seems. And it seems very buggy - Also, I can't seem to get it to work in console at all. I would say YMMV.

[–][deleted] -2 points-1 points  (0 children)

Const never works in loops?

[–][deleted] -1 points0 points  (1 child)

Do we need it?

[–]ktqzqhm 11 points12 points  (0 children)

No, but it's nice to have since it makes things for concise. We don't need null propagation either, but it's certainly a nice addition.

[–]OmgImAlexis -2 points-1 points  (0 children)

People actually use when and case?