This document is an informal specification of the support for access to initializing formal parameters which has been implemented in dart2js
with option --initializing-formal-access
, starting with commit 442fc5. In SDK 1.21 this feature is enabled by default (that is, also without the option) in all tools.
The motivation for having this feature is that it enables less verbose and less repetitive code, and it is a feature that users have frequently requested.
Recall that an initializing formal parameter is a parameter to a generative constructor whose declaration is on the form this.x
for some identifier x
(possibly with a type annotation as in int this.x
or bool this.x(int y)
). At call sites this kind of parameter is passed just like other parameters, but its name (here: x
) must be the name of a field, and that field is implicitly initialized to the