我一直在試圖弄清楚為什么這不起作用,但我不確定。沙箱中的錯(cuò)誤是main.go:16: syntax error: unexpected {, expecting ) 代碼:package mainimport "fmt"type handler func(a func(b int))func HandleSomething(h handler) { //... //d := h(5)//h(5) // ...}func main() { var foo int HandleSomething(handler(func(func(b int){ fmt.Printf("debug: foo in main is %d and %d", foo, b) })))}
Go 中的閉包 - 聲明將函數(shù)作為參數(shù)的函數(shù)
慕標(biāo)琳琳
2021-10-04 15:37:07