Using class members
Objects have members consisting of functions and data (methods andinstance variables, respectively). When you call a method, you _invoke_it on an object: the method has access to that object’s functions anddata.
Use a dot (.
) to refer to an instance variable or method:
var p = Point(2, 2);
// Set the value of the instance variable y.
p.y = 3;
// Get the value of y.
assert(p.y == 3);
// Invoke distanceTo() on p.
num distance = p.distanceTo(Point(4, 4));
Use ?.
instead of .
to avoid an exceptionwhen the leftmost operand is null:
// If p is non-null, set its y value to 4.
p?.y = 4;