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

闭包 #5

Open
QinZonger opened this issue Dec 27, 2018 · 0 comments
Open

闭包 #5

QinZonger opened this issue Dec 27, 2018 · 0 comments
Labels

Comments

@QinZonger
Copy link
Owner

闭包 = 函数 + 函数能够访问的自由变量
自由变量是指在函数中使用的,但既不是函数参数也不是函数的局部变量的变量。

var a = 1;

function foo() {
    console.log(a);
}

foo();

foo 函数可以访问变量 a,但是 a 既不是 foo 函数的局部变量,也不是 foo 函数的参数,所以 a 就是自由变量, 那么,函数 foo + foo 函数访问的自由变量 a 不就是构成了一个闭包。

@QinZonger QinZonger added the ES6 label Dec 27, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant