functiona() {
functionb() {
var b = 234;
}
var a = 123;
}
var glob = 100;
a();
当a函数被定义的时候 define
a函数刚被定义的时候:
a define a.[[scope]] --> 0(第0位) GO {}
//GO:全局global环境 在GO中存储了如图:this,windoe,document,global,a函数
当a函数执行时 doing
a doing a.[[scope]] --> 0(第0位) AO {}
a doing a.[[scope]] --> 1(第1位) GO {}
scope chain 第0位:AO(Activation Object) 激活执行状态
scope chain 第1位:对应global环境
** 例子分析2:**
functiona() {
functionb() {
functionc() {
}
c();
}
b();
}
a();
// 作用域分析
a defined a.[[scope]] -- > 0 : GO
a dong a.[[scope]] -- > 0 : aAO
1 : GO
b defined b.[[scope]] -- > 0 : aAO
1 : GO
b doing b[[scope]] -- > 0 : bAO
1 : aAO
2 : GO
c defined c.[[scope]] -- > 0 : bAO
2 : aAO
3 : GO
c doing c[[scope]] -- > 0 : cAO
1 : bAO
2 : aA0
3 : GO