闭包定义:返回函数的函数就是闭包
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}复制代码