I have the following code appended at the bottom of my markup stack (like a good little web designer :D)…
document.onload = getElements();
var delay = 250;
var open = '';
function cog_slider(element){
if(open == element)
element = '';
setTimeout("animate(" + new Date().getTime() + "," + delay + ",'" + open + "','" + element + "')", 33);
open = element;
}
“cog_slider” is nothing more than a pilot function used for a menu animation process. It’s not too complex, but the thing I’m going cwazy about here is how the variables outside the function definition are being processed (variables “delay” and “open”)…
In my mind, I keep thinking that global variables should have something indicating such, but these variables “delay” and “open” lack this. Are these global variables, then? I’m familiar with seeing things like the word “global” in PHP and such, but is this unnecessary in JavaScript across the board or is this specific case I bring to light here something of a more unorthodox scenario? As you can tell, I’m not the sharpest knife in the drawer when it comes to JavaScript.
But lastly, when functions are slated or initialized through the use of document.onload, does this mean that anything between the actual onload declaration and the function definition itself gets used only once if the function definition has a setTimeout call in it (combined with the document.onload)? The reason I’m asking this is because I’m trying to figure out a way to encapsulate each function, and so far, I’m unable to do that because variables “open” and “delay” seem to be dependent on being processed prior to the function definition and the reason I wish to encapsulate everything is so that I can say I’m awesome. Well, that, and to make life easier down the road with other functions…
Any light you pros around here can shine on this is very appreciated.