On 07/03/2017 12:25 PM, Jordan Harband wrote:
```
const { a } = o;
let { b } = o;
b = 1;
```
seems like a much simpler workaround than adding this complexity to
the language.
I dunno. I've wanted this numerous times. The use case is really
const { a, let b } = complexExpression();
A typical scenario is when I'm splitting something up and returning the
parts, and I want one for a short-lifetime const and the other to update
a state variable.
On the other hand, it reads pretty oddly to me, and I would probably
vote against complicating the parsing for this anyway.
{ const a, let b } = complexExpression();
reads a little better to me. Another alternative would be
const { a } = let { b } = complexExpression();
and I suppose that suggests a better workaround than what I normally
use. Workaround:
let b;
const { a } = { b } = complexExpression();
Or with arrays:
let b;
const [ a ] = [ ,,b ] = complexExpression();
Tangent: it would be nice to have a "don't care" value; those commas are
hard to spot. 'undefined' doesn't work and is too long anyway. _ is ok
if you predeclare with let _; but you can only use it once. This won't work:
const [ _, a, _, b ] = o;
nor will
let _;
const [ _, a ] = [ b, _, c ] = foo();
I guess it's better to *not* predeclare with let, but then you pollute
the global object, and you still can't use it with
const [ _, a ] = foo();
const [ _, b ] = bar();
Given your two examples, I'd find it bizarre for one to work and the
other not, so we'd want to support both. It also raises the question
of declaration-less assignments - `({ a, b } = o);` could become `({
const a, let b } = o);`?
On Mon, Jul 3, 2017 at 10:49 AM, Bob Myers <[email protected]
<mailto:[email protected]>> wrote:
Totally minor, but
```
const {a, b} = o;
b = 1;
```
Complains that `b` is `const` and can't be assigned.
```
let {a, b} = o;
b = 1;
```
Now lint complains that `a` is never modified, and ought to be
`const`.
So I would like to write:
```
const {a, let b} = o;
b = 1;
````
or alternatively
```
let {const a, b} = o;
b = 1;
````
_______________________________________________
es-discuss mailing list
[email protected] <mailto:[email protected]>
https://mail.mozilla.org/listinfo/es-discuss
<https://mail.mozilla.org/listinfo/es-discuss>
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss