VO + [[Scope]]
例子
var x = 10;
function foo() {
var y = 20;
function bar() {
var z = 30;
alert(x + y + z);
}
bar();
}
foo(); // 60
globalContext.VO === Global = {
x: 10
foo: <reference to function>
};
foo.[[Scope]] = [
globalContext.VO
];
fooContext.AO = {
y: 20,
bar: <reference to function>
};
fooContext.Scope = fooContext.AO + foo.[[Scope]] // i.e.:
fooContext.Scope = [
fooContext.AO,
globalContext.VO
];
bar.[[Scope]] = [
fooContext.AO,
globalContext.VO
];
barContext.AO = {
z: 30
};
barContext.Scope = barContext.AO + bar.[[Scope]] // i.e.:
barContext.Scope = [
barContext.AO,
fooContext.AO,
globalContext.VO
];
- "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以上就是Javascript作用域的深入解析(代码示例)的详细内容,更多请关注php中文网其它相关文章!
网站建设是一个广义的术语,涵盖了许多不同的技能和学科中所使用的生产和维护的网站。
关键词:Javascript作用域的深入解析(代码示例)