25 August 2005

JavaScript gotcha

A recent (humbling) discovery: you need to explicitly define looping variables in functions called recursively. So, in the following pseudo-code, the "var" was left out and a single "index" variable will exist across all calls (probably screwing up your intended results):

function recurse(collection)
{
    // Ouch! Forgot the var.
    for (index = 0; index < collection.length; ++index)
    {
        recurse(collection.children);
    }
}

I hate that I still have scoping issues with JavaScript. Curses.

[ posted by sstrader on 25 August 2005 at 11:15:02 AM in Programming ]