On 1/12/25 8:55 PM, H. S. Teoh wrote:

> I wish there was some kind of syntactic sugar for assigning ctor
> parameters to class members.

Amen. Dart provides some help. It's under Generative Constructors here:

  https://dart.dev/language/constructors

class Point {
  // Instance variables to hold the coordinates of the point.
  double x;
  double y;

  // Generative constructor with initializing formal parameters:
  Point(this.x, this.y);
}

The following comment under the next section hints at what happens when a constructor body is provided:

  // Sets the x and y instance variables
  // before the constructor body runs.

Ali

Reply via email to