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

聊一聊什么是闭包? #58

Open
zhuguly-zz opened this issue Aug 5, 2020 · 0 comments
Open

聊一聊什么是闭包? #58

zhuguly-zz opened this issue Aug 5, 2020 · 0 comments

Comments

@zhuguly-zz
Copy link
Owner

闭包是由函数以及创建该函数的词法环境组合而成的,这个环境包含了闭包创建时能够访问的所有局部变量。
函数连同它作用域链上的要使用的变量共同构成闭包,简单来说,函数1中返回了函数2,而函数2中用到了函数1中的局部变量,这就构成了闭包。
一般情况下使用闭包是为了封装数据和暂存数据,也可以让对象拥有私有属性。
题目来自饥人谷

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