typeover
curriculum

Curriculum Types & methods Methods exercise 4 · fill-word

Methods

Make the receiver a POINTER receiver so bump can mutate the caller's Counter. The blank is the type-side modifier. Without it, bump takes a copy and the mutation is invisible to main — same as exercise 6 of theme 3.1, now method-shaped.

TypeScript reference
Fill the blanks →

About this theme

Methods are functions with a receiver — a special argument declared before the function name: func (r Receiver) Foo() { ... }. Two flavours: value receivers (operate on a copy) and pointer receivers (operate on the original). The rule of thumb: use a pointer receiver if you'd modify the receiver, or if the receiver is large enough that copying is wasteful.