[thelist] for loop, array and mouseover teazer

Lee Kowalkowski lee.kowalkowski at googlemail.com
Fri Sep 7 03:18:20 CDT 2007

On 06/09/2007, Chris Price <chris.price at choctaw.co.uk> wrote:
> The above code works fine but I want to include the onMouseOver's in the
> for loop. However if I have: ball_object_array[count].onmouseover =
> function() { changeBall(ball_id_array[count],ballPark); return false }
> count gets returned as 7 every time.

That gives a closure over count, all functions will reference the same
instance of count, with its final value.

You can do something like: .onmouseover = new
Function("changeBall(ball_id_array[" + count + "],ballPark); return


More information about the thelist mailing list