Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > JavaScript > Re: setTimeout(...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 3 of 7 Topic 35462 of 37128
Post > Topic >>

Re: setTimeout() ignored in loop

by Ugo <privacy@[EMAIL PROTECTED] > May 2, 2008 at 09:29 PM

> I have a function called myFunction that can be called once from an
> onclick() or 100 times from a function called  loopFunction which
> contains a for(var i=0;i<100;i++) loop.
> 
> Within myFunction is a setTimeout() function like this:
> 
> setTimeout(function(){shuffleDoor()},1500);

it's preferable:
setTimeout( shuffleDoor, 1500 );

> Now, when I call myFunction from onclick() it waits 1.5 seconds and
> then calls the shuffleDoor function, just as I imagine it should.

ok

> However when I call the function from loopFunction it is called 100
> times but there is no 1.5 second delay between calls.

only the first one, I suppose

> Why is this?

because the elapse time between single call of the loop is infinitesimal,
setTimeout does not stall the script, the script continues immediately
(not
waiting for the timeout to expire); you schedule 100 contem****aneous
actions.
If you want execute the same function every 1,5 sec, the better way is to
use setInterval
 




 7 Posts in Topic:
setTimeout() ignored in loop
Steve <stephen.joung@[  2008-05-02 11:35:53 
Re: setTimeout() ignored in loop
Joost Diepenmaat <joos  2008-05-02 21:14:01 
Re: setTimeout() ignored in loop
Ugo <privacy@[EMAIL PR  2008-05-02 21:29:02 
Re: setTimeout() ignored in loop
Thomas 'PointedEars' Lahn  2008-05-02 22:21:18 
Re: setTimeout() ignored in loop
Steve <stephen.joung@[  2008-05-02 13:02:34 
Re: setTimeout() ignored in loop
Joost Diepenmaat <joos  2008-05-02 22:10:24 
Re: setTimeout() ignored in loop
Gregor Kofler <usenet@  2008-05-03 12:42:22 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Fri Oct 10 15:01:28 CDT 2008.