Created
February 5, 2017 14:51
-
-
Save somandubey/6c612f41417815422a244f63db557d2c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function foo(){ | |
for (var i=1;i<6;i++) { | |
var f = function(i) { | |
var k = function(){console.log(i)}; | |
setTimeout(k,1000*i); | |
} | |
f(i); | |
} | |
} | |
foo(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
original problem -
function foo() { for (var i=1;i<6;i++) { setTimeout(function() { console.log(i) }, 1000*i); } } foo();
Need to print 1 to 5.