Skip to content
New issue

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

解释原因 #586

Open
DarknessZY opened this issue Jul 26, 2023 · 0 comments
Open

解释原因 #586

DarknessZY opened this issue Jul 26, 2023 · 0 comments

Comments

@DarknessZY
Copy link

这段代码会输出函数本身作为变量b的值,并不会被重新赋值为20。这是因为在自执行函数中中,函数的参数和内部局部变量会覆盖全局作用域中的同名变量。在这个自执行函数中,函数名b被定义为函数本身,并形成了一个闭包。当我们尝试将b重新赋值为20时,其实是在修改闭包中的局部变量,而不是全局变量b。因此,输出结果仍然是函数本身。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant