I continue my crusade to the world of JavaScript. Faced the following difficulty:
function stub(callback){ var delay = Math.floor(Math.random()*10000)+1000; var msg = "Message " + delay; setTimeout(stub(callback), delay); callback(msg); } stub( function( msg ){ alert(msg); }); I execute in firefox and firebug shows an error:
too much recursion: setTimeout(stub(callback), delay); How can this be circumvented? Like a recursion and does not smell, just an infinite loop :-)
UPD. Another jamb noticed the delay began to vary from 10,000 to 30,000 milliseconds. but something I do not feel this delay, what could be the problem?)