For reference, I'll give a sample about where a timing issue can occur and how easy it is to prevent any problem in idiomatic JS.
The full source is here: http://forums.asp.net/ShowPost.aspx?PostID=1456947
Once you have got what that does, just focus on this simple fragment:
// Keep order!
fileDsp.innerHTML = "<em>Loading...</em>";
fileImg.src = fileBox.value;
//
Since this code is loading a local file*, assigning to the src property of the image immediately triggers the onload event for the image. But assigning to the innerHTML property too enqueues an interface update. Bottom line, if you revert the order of the statements above, you do not get correct results, because the sequence in which you enqueue events is the sequence in which they get then run!!!
And, this is true for JS in web pages as well as it is true for any ECMA-based language, like it was JS in VRML, like it is AS in Flash, and so on.
I hope this can shed a bit more light, anyway if you guys have any significant sample that you would like to see analyzed and refactored to "true" JS, please don't be shy and post it. IMHO, it might be a very instructive "case-study" for everybody trying to find their way with client-side programming.
-LV
*If the file was not local, the timing issue involved might not show up. Yet, that is the way to go in general, for robust JS programming... We don't need mutexes, neither we miss OO-JS. We better simply know our language...
Julio P. Di Egidio
Software Analyst Programmer
=BUSINESS AND SCIENTIFIC=
=SOFTWARE DEVELOPMENT=
http://julio.diegidio.name
(Peace X Love] = [++1)