Javascript examples for Browser Object Model:Window setTimeout
Read variable in function() with setTimeout(fn())
<html> <head> <meta name="viewport" content="width=device-width, initial-scale=1"> <script type="text/javascript"> window.onload=function(){/*from ww w . j a v a 2s.c o m*/ for(var i=1; i<=3; i++){ (function(num){ setTimeout(function(){ say("No:" + num); }, num * 1000); })(i); } function say(text){ console.log(text); } } </script> </head> <body> </body> </html>