Skip to content

Instantly share code, notes, and snippets.

@iam-peekay
Created April 27, 2016 23:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iam-peekay/a9a74be621f9940335280b57158397a4 to your computer and use it in GitHub Desktop.
Save iam-peekay/a9a74be621f9940335280b57158397a4 to your computer and use it in GitHub Desktop.
var result = [];
for (var i = 0; i < 5; i++) {
result[i] = function () {
console.log(i);
};
}
result[0](); // 5, expected 0
result[1](); // 5, expected 1
result[2](); // 5, expected 2
result[3](); // 5, expected 3
result[4](); // 5, expected 4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment