package mainimport "fmt"// go 回调函数func main() { /* 匿名: 没有名字 匿名对象: 匿名函数: 函数没有名字 通常只能使用一次。 定义的时候直接使用 */ fun1 := func(a, b int) int { fmt.Println("a:", a, "b:", b) return a * b } res2 := oper(1, 2, fun1) fmt.Println(res2) // 3}func oper(m, n int, fun func(int, int) int) int { return fun(1, 2)}
文章来源:智云一二三科技
文章标题:go 回调函数 & 匿名函数
文章地址:https://www.zhihuclub.com/5062.shtml