Forced wait in javascript

I want to make the function wait 1 second before continuing to do this in javascript. For instance:

function DoSomething(){ // wait 1 second //continue we is this function does. } 

Thanks.

+4
source share
1 answer

If I understand you correctly, you need this:

 setTimeout(DoSomething ,1000); 

Edit thanks to Teemu :

 function DoSomething (){ setTimeout(ContinueDoSomething ,1000); } function ContinueDoSomething (){ // ... } 

And even another way may be most effective in some cases:

 function DoSomething (){ setTimeout( function(){ // ... },1000); } 
+11
source

Source: https://habr.com/ru/post/1485589/


All Articles