Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 9f960a6

Browse files
author
Tony Sansone
committedMay 1, 2024
Clean up code excerpts
1 parent 857c323 commit 9f960a6

File tree

1 file changed

+14
-17
lines changed

1 file changed

+14
-17
lines changed
 

‎src/content/language/constructors.md

+14-17
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ you must manually pass in all super constructor parameters.
175175
If the super-constructor invocation includes positional arguments,
176176
super-initializer parameters can't be positional.
177177

178-
<?code-excerpt "super_initializer_parameters.dart (positional)" plaster="none"?>
178+
<?code-excerpt "super_initializer_positional_parameters.dart (positional)" plaster="none"?>
179179
```dart
180180
class Vector2d {
181181
final double x;
@@ -211,7 +211,7 @@ between named super parameters (`super.y` in the next example)
211211
and named arguments to the super constructor invocation
212212
(`super.named(x: 0)`).
213213

214-
<?code-excerpt "super_initializer_parameters.dart (named)" plaster="none"?>
214+
<?code-excerpt "super_initializer_named_parameters.dart (named)" plaster="none"?>
215215
```dart
216216
class Vector2d {
217217
// ...
@@ -231,11 +231,9 @@ class Vector3d extends Vector2d {
231231

232232
### Redirecting constructors
233233

234-
Sometimes a constructor's only serves to redirect to another
235-
constructor in the same class. A redirecting constructor's body is
236-
empty, with the constructor call
237-
(using `this` instead of the class name)
238-
appearing after a colon (:).
234+
A constructor might redirect to another constructor in the same class.
235+
A redirecting constructor has an empty body.
236+
The constructor uses `this` instead of the class name after a colon (:).
239237

240238
<?code-excerpt "point_redirecting.dart"?>
241239
```dart
@@ -268,8 +266,7 @@ class ImmutablePoint {
268266
```
269267

270268
Constant constructors don't always create constants.
271-
For details, see the section on
272-
[using constructors][].
269+
To learn more, consult the section on [using constructors][].
273270

274271
### Factory constructors
275272

@@ -292,10 +289,10 @@ You can also handle late initialization of a final variable
292289
with [`late final`][late-final-ivar] (carefully!).
293290
:::
294291

295-
In the following example includes two factory constructors.
292+
The following example includes two factory constructors.
296293

297294
* `Logger` factory constructor returns objects from a cache.
298-
* The `Logger.fromJson` factory constructor initializes a final variable
295+
* `Logger.fromJson` factory constructor initializes a final variable
299296
from a JSON object.
300297

301298
<?code-excerpt "logger.dart (constructors)"?>
@@ -325,10 +322,10 @@ class Logger {
325322
```
326323

327324
:::warning
328-
Factory constructors can't access to `this`.
325+
Factory constructors can't access `this`.
329326
:::
330327

331-
Invoke a factory constructor just like you would any other constructor:
328+
Use a factory constructor as any other constructor:
332329

333330
<?code-excerpt "logger.dart (logger)"?>
334331
```dart
@@ -366,18 +363,18 @@ class PointA {
366363
### Use initializing formal parameters
367364

368365
To simplify the common pattern of assigning a constructor argument
369-
to an instance variable,
370-
Dart has *initializing formal parameters*.
366+
to an instance variable, Dart has *initializing formal parameters*.
371367

372368
In the constructor declaration, include `this.<propertyName>`
373369
and omit the body. The `this` keyword refers to the current instance.
374370

375371
When the name conflict exists, use `this`.
376372
Otherwise, Dart style omits the `this`.
377-
An exception exists for the generative constructor:
373+
An exception exists for the generative constructor where
378374
you must prefix the initializing formal parameter name with `this`.
379375

380-
Certain constructors and parts of constructors can't access `this`:
376+
As noted earlier in this guide, certain constructors
377+
and certain parts of constructors can't access `this`. These include:
381378

382379
* Factory constructors
383380
* The right-hand side of an initializer list

0 commit comments

Comments
 (0)
Please sign in to comment.