1.4.1中关于闭包的例子和本地测试结果不一致

Author: baiyeidkCreated Jul 25, 2025Updated Apr 19, 2026
go
func main() {
    for i := 0; i < 3; i++ {
        defer func(){ println(i) } ()
    }
}
// Output:
// 3
// 3
// 3

这个例子我在本地测试如下

Image

是因为高版本的go对循环的局部变量做了新的机制吗?

Source: chai2010/advanced-go-programming-book