闭包
package main
import "fmt"
func aaa() {
i := 1
defer fmt.Println("aaa:", i) //1
i++
}
func bbb() {
i := 1
defer func() {
fmt.Println("bbb:", i) // 2
}()
i++
}
func main() {
aaa()
bbb()
}
package main
import "fmt"
func aaa() {
i := 1
defer fmt.Println("aaa:", i) //1
i++
}
func bbb() {
i := 1
defer func() {
fmt.Println("bbb:", i) // 2
}()
i++
}
func main() {
aaa()
bbb()
}