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

闭包 #4

Open
into-piece opened this issue Jun 20, 2019 · 0 comments
Open

闭包 #4

into-piece opened this issue Jun 20, 2019 · 0 comments

Comments

@into-piece
Copy link
Owner

into-piece commented Jun 20, 2019

闭包是啥,如何形成

闭包是有权访问另一个函数作用域中的变量的函数:当函数1向外暴露了可以改变内部局部变量的方法(内部匿名函数,外部函数2接受匿名函数,匿名函数作用域链在初始化时包含了函数1的变量对象,可以调用函数1所有的内部变量。一般函数执行完局部活动对象就会进行销毁,内存仅仅只会保存全局作用域,但函数1在执行完毕其活动对象也不会进行销毁,因为匿名函数的作用域链仍然在对其进行调用。(参考高程

作用

可以读取函数内部的变量,让变量的值始终保持在内存中。栗子:实现函数curry化。

注意

内存泄露。

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