这就是我定义函数的方式,变量x,y,z
是用一些整数定义的。
var a = 0;
var x = 1;
var y = 2;
var z = 3;
function f(n) {
a = n;
}
function g(){
console.log(a);
}
function h(){
f(x); g();
}
function k() {
var a = 0; g(); f(y);
}
f(z); g(); k(); g(); h(); g();
以下是我对上面的代码是否为动态范围的想法:
f(z){
a = z; // The value of a became z
}
g(){
console.log(a); // Printing out the value of z
}
k(){
var a = 0;
g(){
console.log(a); // Printing out 0
}
f(y){
a = y; // Assign the value of y to the variable a initialized 5 lines above
}
}
g(){
console.log(a); // Printing out the value of z
}
h(){
f(x){
a = x;
}
g(){
console.log(a) // Printing out the value of x
}
}
g(){
console.log(a) // Printing out value of z or x ??
}
不确定最后一个 console.log 会输出什么。