Object oriented

constructor

The function that runs when you create an object with newobj.

Syntax

define constructor(<type> <arg>, ...);
    redefine self.<field> is <arg>;
end;

How she behaves

  • Parameters are typed, like a function.
  • Use self to write the object's fields.
  • newobj ClassName(...) calls this constructor.

Example

define constructor(str name, num age);
    redefine self.name is name;
    redefine self.age is age;
end;

See also