Javascript will work from top to bottom if what you have in this case is a lock. If so, you can simply put the code directly under the if statement, outside the timeout, and it will work fine. If it is asynchronous, you can use a callback that fires when the first function is completed to start the second function.
-, , . write() AJAX , - . , , , .
JS
var write = function (v, cb) {
setTimeout(function() {
document.write(v);
cb && cb();
}, 1000);
}
if (true) {
write("I'm not blocking, blah<br/>", function() {
document.write("Running<br/>");
});
}
if (true) {
document.write("I'm blocking, blah<br/>");
}
document.write("Running<br/>");
I'm blocking, blah
Running
I'm not blocking, blah
Running
http://jsfiddle.net/robert/vvmyk/