bar 函数里的var a=30是作用在AO该函数作用域内,与GO 中的 a=10 ,变量与值都不同,是不同的变量,需要重新声明,除非在外界把参数传进去。
过程 :
预解析: GO{
foo:function(){}
bar:function(){}
a:undefined;--->10
}
执行:1.bar()
bar{
AO : a: undefined-->30
foo()}
foo :console.log(a) 没找到 a 故报undefined;
GO AO也叫:词法作用域链