回调函数:函数A作为参数传入另一个函数B中被调用,则A叫做回调函数,B叫做高阶函数
package main
import "fmt"
func test(x,y int,callback func(x,y int)int) int {
return callback(x,y)
}
func add(x,y int) int {
return x+y
}
func main() {
x,y:=1,2
fmt.Println(test(x,y,add))
}
微信扫一扫
回调函数:函数A作为参数传入另一个函数B中被调用,则A叫做回调函数,B叫做高阶函数
package main
import "fmt"
func test(x,y int,callback func(x,y int)int) int {
return callback(x,y)
}
func add(x,y int) int {
return x+y
}
func main() {
x,y:=1,2
fmt.Println(test(x,y,add))
}
相关推荐