Suggestion: multiple keys, same value for object literals
akx opened this issue · 2 comments
akx commented
I have some code with something like this:
{ # coco
foo: a
bar: a
baz: b
quux: b
eggs: c
}
But I think it'd be more elegant to be able to declare the multiple keys in a single k/v pair. Syntax suggestion (currently parse errors):
{ # coco
(foo, bar): a
(baz, quux): b
eggs: c
}
Apropos: while thinking about other syntaxes for this, I noticed this -- is it intentional that
{ # coco
[foo, bar]: a
[baz, quux]: b
eggs: c
}
parses into
{ // js
a: [foo, bar],
b: [baz, quux],
eggs: c
}
satyr commented
Seems too narrow to dedicate a new syntax. Why not:
new
@foo = @bar = a
@baz = @quux = b
@eggs = c
or
with {eggs: c}
&foo = &bar = a
&baz = &quux = b
is it intentional
Yes. {[b]:a}
desugars to {a: [b]:a}
, which is useful when destructuring:
$ coco -bce '{[b]:a} = c'
var a, b;
a = c.a, b = a[0];
akx commented
Ah, right, forgot the destructuring usecase. Anyway, those suggestions look good. Thanks :)