Curriculum Types & methods Methods
Methods
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.
9 ready
01
pick one Translate the TypeScript method greet on User into the
02
pick oneGo methods can take their receiver by VALUE (`func (c Counter)
03
pick oneGiven a method declared with a POINTER receiver:
04
fill blanks Make the receiver a POINTER receiver so bump can mutate the
05
fill blanksInside a method body, the receiver acts as the conventional
06
type one line Write the METHOD SIGNATURE (just the func (...) header) for a
07
type one line Write the call to p.area() and print the result. area is a
08
write a programWrite a complete program that:
09
write a programTheme capstone: a small Stack-of-int implementation with