Next: , Previous: , Up: Structs   [Contents][Index]


20.5.18 Methods

Methods in structs can be defined using the method keyword in definitions like this:

method identifier = function_body

where function_body is the body of a function. See Function Declarations.

When invoked, a method gets an implicit last argument which is the struct value whose method is being used.

Methods can refer to the fields of the containing struct type that have been defined before the method itself, by name.

Additionally, the containing struct can be referred explicitly under the name SELF in the body of the method. SELF has type any.