dart-lang / dart-lang/language

Support rest parameter syntax like Javascript.

Open
#893 6 comments 4 reactions 0 assignees View on GitHub
feature
Dominant language
TeX
Stars
2.9k
Forks
239
Avg merge
2d 18h
Merged PRs (30d)
14

Description

I posted a issue about spread syntax support in dart (https://github.com/dart-lang/language/issues/891), it was support in dart 2.3 acturally. Now it comes to it's partner `rest parameter`.

I try to write the following code, but it has syntax error. Is there some simple and clean syntax to achieve the same goal like javascript?

```dart
class Person {
final String name;
final int age;

Person({this.name, this.age});

@override
String toString() {
print('name: ${name}, age: ${age}');
}
}

main() {

var data = {'name':"hello", 'age':18, 'sex':'male'};
var person1 = Person(data);
var person2 = Person(...data);
var person3 = Person({...data});
}
```
![image](https://user-images.githubusercontent.com/2276718/77388953-9cd23800-6dcc-11ea-87dc-c585c5e36b02.png)

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/rest_parameters

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.