Based on what you are saying, you are simply trying to defer execution inside a function.
Say, for example, you want to trigger an alert, and after 2 seconds, a second warning:
alert("Hello")
sleep
alert("World")
In javascript, the only 100% way to accomplish this is to split the function.
function a()
{
alert("Hello")
setTimeout("b()",3000);
}
function b()
{
alert("World");
}
setTimeout
function a()
{
alert("Hello");
setTimeout(function() {
alert("World");
},3000);
}