转到:具有接收器功能的函数指针

Can I set function pointer to function with receiver simpler than creating function around it?

package main

import "fmt"

type hello struct {
  name string
}

func (obj *hello) hello() {
  fmt.Printf("Hello %s
", obj.name)
}

func ntimes(action func (), n int) {
  for i := 0; i < n; i++ {
    action()
  }
}

func main() {
  obj := hello{"world"}
  // Can I do following simpler?
  ntimes(func() {obj.hello();}, 3)
}

Not right now. But with Go 1.1 this will be possible. Go 1.1 Function Calls

Go 1.1 will be ready when the blue line touches zero.