Today, we write a javascript code like this:
Function (){
...
For (I = 0; I <ABC. length; I ++ ){
...
B ();
...
}
...
}
Function B (){
...
For (I = 0; I <def. length; I ++ ){
...
}
...
}
These two JavaScript Functions. However, function a only executes a loop and jumps out of the for loop. It should have executed multiple cycles.
I checked the code all day and finally found the cause of the error.
Originally, there was a problem with the lifecycle management of JavaScript variables. The local variables I of functions a and B, JavaScript considers them to be the same variable.
In this way, after the loop is executed in function B, the I value in function a has exceeded the condition, so each time the for loop of function a is executed only once.
After I change I in function B to J, it will be normal!
It is indeed against common sense to manage the lifecycle of such variables. I am using IE7. I don't know if this is a javascript specification? Or is there a problem with the implementation of IE7 itself?
It seems that we must avoid using variables with the same name in Javascript encoding to avoid variable name conflicts. This problem is extremely hidden and hard to find!