全局上下文有三个非常重要的属性:
1.变量对象
2.作用域链
3.this指向
var a = 1function sum () {var b = 2;return a + b;}sum();
sum.[[scope]] = {
globalContext.VO
}
ECS = [
globalContext,
sumContext
]
sumContext = {
AO:{
arguments:{
length: 0
},
b: undefined
},
Scope: [AO, sum.[[scope]]]
}
sum执行的时候,给b赋值,把AO加到上下文的scope中。执行时先在AO中查找变量,没有再向上级查找
AO: {
arguments:{
length: 0
}
b: 2
}
sum执行完代码销毁,出栈
ECS.pop();