/* Go 语言可以很灵活的创建函数,并作为另外一个函数的实参*/
package main
import (
"fmt"
)
type cb func(int) int
func main() {
fmt.Print("执行开始调用函数作为参数传递->")
testCallback(1,callback)
testCallback(2, func(x int) int {
fmt.Printf("我是回调,x:%d\n", x)
return x
})
}
func testCallback(x int, f cb) {
f(x)
}
func callback(x int) int{
fmt.Printf("我是回调函数 %d\n",x)
return x
}