I have a clock function that works well. I extended the function in order to toggle between a 12 hour clock and a 24 hour clock. An error occurs when I use the setTimeout function. The error tells me that the variable I used does not exist. Can I not pass a variable in setTimeout(). var newTime = timeType; setTimeout('startclock(newTime)',1000);
The setTimeout when called is saying newTime is undefined.
The above is equivilant of doing this:
The setTimeout (I am blank here, blame it on friday before long weekend so terms may be wrong) is bascially executes in a seperate thread/instance and is not executed inside of that function that is is declared.
So by building up the string it is basically hardcoding that value into the call
looks like
It gets even better with closures and OO JavaScript.