Hacker News new | past | comments | ask | show | jobs | submit login

That's how you define a method in Go. The local to the left of the function name is the receiver (what `this` would be in Java).

Note that there are a few odd bits to Go methods: the receiver can be a value or a pointer, and if the receiver is a pointer it might be null, because method calls on concrete types are statically dispatched so

    type S struct{}
    func (self *S) Foo() {
        fmt.Printf("%v\n", self)
    }
    func main() {
        var s *S
        s.Foo()
    }
will print "<nil>".



Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: