We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
因为在defer函数定义时,对外部变量的引用是有两种方式的,分别是作为函数参数和作为闭包引用。 使用匿名函数的话是没有将参数传递过去的,在最后调用是才去拿值。
import "fmt" func main() { name := "go" defer func(name string) { fmt.Println(name) // 输出: go }(name) name = "python" fmt.Println(name) // 输出: python } // 这样输出就是python go
The text was updated successfully, but these errors were encountered:
关于这个问题,我加了两篇 defer 的文章,你可以看一下
Sorry, something went wrong.
No branches or pull requests
因为在defer函数定义时,对外部变量的引用是有两种方式的,分别是作为函数参数和作为闭包引用。
使用匿名函数的话是没有将参数传递过去的,在最后调用是才去拿值。
The text was updated successfully, but these errors were encountered: