[thelist] JavaScript Array and Split

Rick den Haan rick.denhaan at gmail.com
Sun Feb 11 18:21:27 CST 2007


Christie wrote:
> I can't put anything into the existing external files, or am I
> misunderstanding your advice?  I'm thinking I'm lost at how I read the
cData
> array in external1.js into a second file and then split and output within
> that second file.
> 
> Christie Mason

Christie,

If you can't put anything in the external files, disregard my last advice :)

If a variable is defined in an external file, as long as it's not within a
function, it is accessible in the other javascript code as if it was in the
same file.

So, if you have one file (external1.js) that contains the cData array, and
another file (main.js) that contains the functions to process it, all your
work should be done for you. However, it is quite possible that main.js is
loaded, and your code executed, before external1.js is done loading. In that
case, the cData array doesn't exist yet, or it might be incomplete.

One thing you could do, is run a check on that. If your code to process the
cData array is a function, I suggest you put an if-statement to do so at the
beginning of the function:

function doSomething()
{
    if (typeof cData == "undefined")
    {
        setTimeout("doSomething()", 100);
        return;
    }

    // process cData array
}

If the cData array doesn't exist (yet), it retries in 100 milliseconds and
aborts the current attempt.

HTH,
Rick.




More information about the thelist mailing list