Scope = VO + All Parent VOs 这是什么意思?孬懂

发布于 2022-09-11 14:49:30 字数 108 浏览 17 评论 0

Scope = VO + All Parent VOs
scopeChain = [ [VO] + [VO1] + [VO2] + [VO n+1] ];
全都是变量对象的集合 区别在哪里?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

孤城病女 2022-09-18 14:49:30

在进入上下文,AO/VO创建之后,上下文的Scope属性 =AO|VO + 函数[[scope]]

 
活跃对象是Scope数组的第一个元素。添加在作用域链的最前面 比如 three() Scope Chain = [ [three() VO] + [two() VO] + [one() VO] + [Global VO] ];

Scope = [AO].concat([[Scope]]);  <---此特性对处理标识符非常重要

处理标识符其实就是一个确定变量(或者函数声明)属于作用域链中哪个变量对象的过程。

var x = 10;
function foo() {
var y = 20;
function bar() {

var z = 30;
alert(x +  y + z);

}
bar();
}
foo(); // 60

全局上下文

global_Context.VO===global={
    x=10
    foo:
}

foo 函数创建

foo.[[scope]]={
    global_context.VO
}

foo函数激活(进入上下文时)

foo_context.AO={
    y:20
    bar:
}

foo函数上下文的作用域链


foo_context.scope=foo_context.AO+foo.[[scope]]

foo_context.scope=[
    foo_context.AO,
    global_context.VO
    ]

bar 函数创建

bar.[[Scope]] = [
  fooContext.AO,
  globalContext.VO
];

bar激活

barContext.AO = {
  z: 30
};

bar函数上下文的作用域链

barContext.Scope = barContext.AO + bar.[[Scope]] // i.e.:
 
barContext.Scope = [
  barContext.AO,
  fooContext.AO,
  globalContext.VO
];

如下是x y z标识符的查询过程:

"x"

  barContext.AO // not found
  fooContext.AO // not found
  globalContext.VO // found - 10

"y"

  barContext.AO // not found
  fooContext.AO // found - 20

"z"

  barContext.AO // found - 30




~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文