Created
December 25, 2011 15:53
-
-
Save sri-rang/1519452 to your computer and use it in GitHub Desktop.
Functional Programming in JavaScript - 9
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
<div id="redBox1" class="redBox"></div> | |
<div id="redBox2" class="redBox"></div> | |
<div id="redBox3" class="redBox"></div> | |
<div id="greenBox1" class="greenBox"></div> | |
<div id="greenBox2" class="greenBox"></div> | |
<div id="greenBox3" class="greenBox"></div> | |
<script> | |
(function () { | |
for (var i = 1; i <= 3; i++) { | |
var redBoxId = "redBox" + i; | |
document.getElementById(redBoxId).onclick = function () { | |
console.log(redBoxId + " was clicked"); | |
}; | |
var greenBoxId = "greenBox" + i; | |
document.getElementById(greenBoxId).onclick = (function (greenBoxId) { | |
return function () { | |
console.log(greenBoxId + " was clicked"); | |
} | |
})(greenBoxId); | |
} | |
})(); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment