閉包定義:返回函式的函式就是閉包
func main() {
name := "zhe"
zhe := myMoney(name)
zhe(999999)
zhe(888888)
m := zhe(66666)
fmt.Printf("%s的錢是%d\n", name, m)
}複製程式碼
func myMoney(name string) func(n int) int{
var m = 0
f := func(n int) int{
m += n
return m
}
return f
}複製程式碼