Go 1.1: Use method values to simpler code where possible
matryer opened this issue · 0 comments
Go 1.1 now implements method values, which are functions that have been bound to a specific receiver value. For instance, given a Writer value w, the expression w.Write, a method value, is a function that will always write to w; it is equivalent to a function literal closing over w:
func (p []byte) (n int, err error) {
return w.Write(p)
}
Method values are distinct from method expressions, which generate functions from methods of a given type; the method expression (_bufio.Writer).Write is equivalent to a function with an extra first argument, a receiver of type (_bufio.Writer):
func (w *bufio.Writer, p []byte) (n int, err error) {
return w.Write(p)
}
Updating: No existing code is affected; the change is strictly backward-compatible.