Run a function by a specified number of times with setTimeout(fn(), time) - Javascript Browser Object Model

Javascript examples for Browser Object Model:Window setTimeout

Description

Run a function by a specified number of times with setTimeout(fn(), time)

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
      <script type="text/javascript">
var foo = function() {//from   ww w .  j  av a2s.  c  o m
    console.log(new Date().getTime());
};
(function(count) {
    if (count < 5) {
        foo();
        var caller = arguments.callee;
        window.setTimeout(function() {
            caller(count + 1);
        }, 1000);
    }
})(0);

      </script> 
   </head> 
   <body>  
   </body>
</html>

Related Tutorials