Last active
June 20, 2016 10:35
-
-
Save DaveMBush/79dcd8c1fa905d1720dd0798ba6fac18 to your computer and use it in GitHub Desktop.
This file contains 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
for(var i = 0;i < 10;i++){ | |
$.ajax({ | |
url: /* url goes here */, | |
success: function (moduleHtml) { | |
console.log(i); | |
} | |
}); | |
} |
This file contains 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
for(var i = 0;i < 10;i++){ | |
var img = new Image(); | |
img.onload = function(){ | |
alert(testArray[i]); | |
} | |
} |
This file contains 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
for(var i = 0;i < 10;i++){ | |
(function(ii){ | |
setTimeout(function(){ | |
console.log(ii); | |
},1000); | |
})(i); | |
} |
This file contains 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
for(var i = 0;i < 10;i++){ | |
var ii = i; | |
setTimeout(function(){ | |
console.log(ii); | |
},1000); | |
} |
This file contains 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
for(var i = 0;i < 10;i++){ | |
let ii = i; | |
setTimeout(function(){ | |
console.log(ii); | |
},1000); | |
} |
This file contains 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
for(var i = 0;i < 10;i++) { | |
try{throw i} | |
catch(ii) { | |
setTimeout(function(){ | |
console.log(ii); | |
},1000); | |
} | |
} |
This file contains 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
for(var i = 0;i < 10;i++){ | |
setTimeout(function(){ | |
console.log(i); | |
},1000); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This code is to support the article "Why does JavaScript loop only use last value?" which will be posted on 6/16/2016