What is the difference between a method receiver and a parameter?

Looking at the Go documentation below, it's hard for me to understand the difference between recipients and parameters:

func (p *Page) save() error { filename := p.Title + ".txt" return ioutil.WriteFile(filename, p.Body, 0600) } 

This method signature reads: This is a method called save that takes a pointer to p as the receiver. It takes no parameters and returns a type error value.

+4
source share
1 answer

The receiver is similar to this in C #: in xf(a, b, c) receiver is x , and the arguments are a , b and c . When the function is executed, the parameters refer to copies of the arguments. An important difference between the receiver and the parameters is that when the receiver is an interface type on the call site, the called function is defined dynamically, not statically.

+8
source

Source: https://habr.com/ru/post/1494132/


All Articles