Created
January 6, 2012 08:13
-
-
Save psiborg/1569634 to your computer and use it in GitHub Desktop.
JS Closure
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 link = document.createElement("a"); | |
link.innerHTML = "Link " + i; | |
link.href = "#"; | |
link.onclick = (function (num) { | |
return function () { | |
alert("This is link " + num); | |
return false; | |
}; | |
}(i)); | |
document.body.appendChild(link); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment