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

浅谈作用域链查找机制。 #21

Open
CodeRookie262 opened this issue Jan 13, 2021 · 1 comment
Open

浅谈作用域链查找机制。 #21

CodeRookie262 opened this issue Jan 13, 2021 · 1 comment

Comments

@CodeRookie262
Copy link
Owner

当我们要访问或者设置一个变量时,发现在当前作用域并未声明该变量却可以正常操作,有的时候却会报错,这些都和作用域链查找机制有关,作用域链是怎么回事呢,它又是如何进行查找的呢?

@CodeRookie262
Copy link
Owner Author

作用域链查找就是假如函数在执行过程中当前上下文中的 AO 中查找不到对应的变量就会通过 Spoce-chain 进行向上查找,直到找到这个变量为止。如果最后走到了全局变量对象 VO(G) 中依然还是找不到这个对象就会报错 Uncaught ReferenceError: xxx is not defined;设置变量也是一样的道理,当前上下文中的 AO 中查找不到对应的变量就会通过 Spoce-chain 进行向上查找,直到找到这个变量为止。如果最后走到了全局变量对象 VO(G) 中依然还是找不到的话就会在全局变量对象VO(G)中声明同名变量并且设置值。

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