I have a script that I need to bump out of the javascript execution queue. I have found that I can do this with a couple methods.
alert();//of course we can't use this one.
setTimeout(function(){
someScript();//works, but are there vulnerabilites?
}, 1);
What other methods are there and what is the correct way to bump out of the javascript execution queue?
If setTimeout is the best option, what are the vulnerabilities of using setTimeout? Are there possible future problems, possibility that the code in the timeout won't get called, speed issues, etc.
setTimeout is the typical way of interrupting the execution flow. alert() is not the same thing, it is synchronous - it will stop your code until OK is pressed, and resume where it left off. When you use setTimeout, that frees up the thread to go execute another section of code.
The only vulnerabilities are not knowing what you are doing. Coding async is a little trickier than coding sync. And you have to watch your context, because using "this" won't work:
object = {
firstMethod: function(){
setTimeout(function(){
this.secondMethod(); // won't work!
}, 30);
},
secondMethod: function(){}
}