- Key features of methods
- See also Functions doc
- A function attached to a type
- Almost anything can have methods (attached functions)
- structs (obvious), numbers, functions, channels
- CANNOT attach to interfaces
- Method attached to a function allow decorating, proxying, ...
- Every type has a (possibly empty) method set associated
- TODO: mention "receiver"
- Think of it like passing the receiver as first arg
type Car struct {
}
func (c Car) DoFoo(arg int) int {
// ...
}
car := Car{}
_ = car.DoFoo(7)
// equivalent to: GenerateDoFoo(car, 7)
TODO: pointer receiver TODO: non-pointer receiver
TODO ...