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

什么是词法作用域 #31

Open
suukii opened this issue Jul 21, 2020 · 0 comments
Open

什么是词法作用域 #31

suukii opened this issue Jul 21, 2020 · 0 comments

Comments

@suukii
Copy link
Owner

suukii commented Jul 21, 2020

作用域是定义变量的一块区域,它规定了变量的访问规则,也就是当前执行的代码能够访问哪些变量。

JS 采用的词法作用域,也就是静态作用域,是指变量的访问规则在词法分析阶段就已经决定了,也就是说,我们写代码、定义函数的时候它们的作用域就已经确定了,函数的作用域取决于它定义的位置,而与它调用的位置无关。

动态作用域

与之相对的是动态作用域,是指函数的作用域要在函数调用时才能确定。

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

No branches or pull requests

1 participant