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

请谈谈你对闭包的理解。 #296

Open
pwstrick opened this issue Jul 16, 2019 · 2 comments
Open

请谈谈你对闭包的理解。 #296

pwstrick opened this issue Jul 16, 2019 · 2 comments
Labels
JavaScript JavaScript类的题目

Comments

@pwstrick
Copy link
Owner

请谈谈你对闭包的理解。

@pwstrick pwstrick added the JavaScript JavaScript类的题目 label Jul 16, 2019
@pwstrick
Copy link
Owner Author

在 JavaScript 中,根据词法作用域的规则,内部函数总是可以访问其外部函数中声明的变量,当通过调用一个外部函数返回一个内部函数后,即使该外部函数已经执行结束了,但是内部函数引用外部函数的变量依然保存在内存中,把这些变量的集合称为闭包。

@pwstrick
Copy link
Owner Author

内部函数访问了外部函数作用域中的变量后,并且在全局作用域中能访问该内部函数,那么即使外部函数执行结束了,这些变量还会滞留在内存中。

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

No branches or pull requests

1 participant