I dun a DIP, possibly the best DIP ever

Sebastiaan Koppe mail at skoppe.eu
Sun Apr 26 11:13:25 UTC 2020


On Sunday, 26 April 2020 at 10:20:49 UTC, Walter Bright wrote:
> On 4/24/2020 6:31 PM, Manu wrote:
>> C++ uses `...`, and they are the only language that has 
>> anything remotely like this.
>> Javascript also uses `...` for something similar-ish, so the 
>> web guys should find it familiar too.
>
> I don't remember Javascript doing that, though it's been 20 
> years since I worked on the JS compiler. Maybe it's a later 
> addition.

It is a recent addition, ES6 I believe.

They use it in destructuring:

```
const {a, b, rest...} = {a:1, b:2, c:3, d:4}; // rest == {c:3, 
d:4}
```

and in expanding arrays

```
function foo(a,b) {}
const ab = [1,2];
foo(...ab);
```

or objects

```
const ab = {a: 1, b: 2};
const cd = {...ab, c:3, d:4}; // cd == {a:1, b:2, c:3, d:4}
```
```




More information about the Digitalmars-d mailing list