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
}
On a different script page, that includes the above page when I do the below, I have no values in array:
this.callingFunction = function(){
this.runThisFunctionOnCall();
alert(array1.length); shows 0
}
Brian Tompsett - 汤莱恩
5,92772 gold badges64 silver badges135 bronze badges
asked Apr 22, 2011 at 20:56
Asim Zaidi
28.5k49 gold badges140 silver badges224 bronze badges
1 Answer 1
The variable array1 is a local variable inside the function runThisFunctionCall so you can not see it outside the function and that leads to array1 in your lower code being another array1 and not the same as in the function and having the length 0 because there are no elements in it.
Here is some explaining: http://www.webdevelopersnotes.com/tutorials/javascript/global_local_variables_scope_javascript.php3
answered Apr 22, 2011 at 21:01
mylopeda
1551 gold badge2 silver badges13 bronze badges
Sign up to request clarification or add additional context in comments.
1 Comment
c-smile
According to code this "The variable array1 is a local variable inside the function runThisFunctionCall" is simply wrong. And before "having the length 0" you will get "variable not found" exception. So it is not correct either.
lang-js
runThisFunctionOnCalldoesn't return anything. Does it change a global variable?