-
Notifications
You must be signed in to change notification settings - Fork 1
Closed
Description
Scope of Change
A compact assignment syntax for member initialization in constructors and methods will be added.
Rationale
Less $this.member= $member; typing - especially in value objects.
Functionality
The $this.member notation is used to describe the argument passed to this parameter will end up in the member variable named member.
public class Person {
protected string $name;
public __construct($this.name) { }
}
// Equivalent of
public class Person {
protected string $name;
public __construct(string $name) {
$this.name= $name;
}
}This notation may be combined with regular parameters:
public class Person {
protected static int $nextId= 0;
protected int $id;
protected string $name;
public __construct($this.name, int $id= -1) {
$this.id= -1 === $id ? ++self::$nextId : $id;
}
}Security considerations
n/a
Speed impact
None, resolved during compile time.
Dependencies
n/a
Related documents
- Dart's "compact constructor form".
- RFC Compact method syntax #241 - Compact method syntax