Advertisement
Guest User

Untitled

a guest
Oct 26th, 2014
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.58 KB | None | 0 0
  1. for (var i = 1; i <= 10; i++) {
  2. setTimeout(function(j) {
  3. console.log(j);
  4. }(i), 1000);
  5. }
  6.  
  7. for (var i = 1; i <= 10; i++) {
  8. setTimeout(function(j) {
  9. return function() {
  10. console.log(j);
  11. }
  12. }(i), 1000 * i); // Delay
  13. }
  14.  
  15. var i = 0;
  16. function start() {
  17. setTimeout(function() {
  18. i++;
  19. console.log(i);
  20. // If we haven't reached our limit, start again
  21. if(i < 10) start();
  22. }, 1000);
  23. }
  24. start();
  25.  
  26. for (var i = 1; i <= 10; i++) {
  27. setTimeout(function(j) {
  28. console.log(j);
  29. }(i), 1000 * i);
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement