this.runThisFunctionOnCall = function(){
//does something and ends up with these arrays of count 1
// arrays.length = 1 (always)
array1;
array2;
array3;
alert(array1.length); // shows 1 here
}
在另一个脚本页面上,当我执行下面的操作时,包括上面的页面,我在数组中没有值。
this.callingFunction = function(){
this.runThisFunctionOnCall();
alert(array1.length); shows 0
}
答案 0 :(得分:3)
变量array1是函数runThisFunctionCall中的一个局部变量,所以你不能在函数外面看到它,导致你的下层代码中的array1是另一个array1,而不是函数中的array1,长度为0因为那里不是其中的元素。
以下是一些解释:http://www.webdevelopersnotes.com/tutorials/javascript/global_local_variables_scope_javascript.php3