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

JavaScript的作用域与作用域链 #3

Open
GGXXMM opened this issue Aug 4, 2019 · 0 comments
Open

JavaScript的作用域与作用域链 #3

GGXXMM opened this issue Aug 4, 2019 · 0 comments
Labels
⭐️ js js knowledge

Comments

@GGXXMM
Copy link
Owner

GGXXMM commented Aug 4, 2019

作用域

作用域可以理解为上下文声明的变量和作用范围。js函数中的隐式属性[[scope]]存储的对象就是作用域,其中分为函数作用域和全局作用域。

作用域链

当局部函数查找某一属性或方法时,如果当前作用域没查找到,就会向上查找上层作用域,直至全局作用域,这样就形成了作用域链。

function a() {
  function b() {
    var b = 234;
    console.log(a);// 123
    console.log(glob);// 100
  }
  var a = 123;
  b();
}
var glob = 100;
a();

a函数的作用域链:
image
b函数的作用域链:
image

@GGXXMM GGXXMM added the ⭐️ js js knowledge label Dec 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
⭐️ js js knowledge
Projects
None yet
Development

No branches or pull requests

1 participant