Skip to content

Instantly share code, notes, and snippets.

@hammerdr
Created September 19, 2010 16:12
Show Gist options
  • Save hammerdr/586875 to your computer and use it in GitHub Desktop.
Save hammerdr/586875 to your computer and use it in GitHub Desktop.
var methods = [];
for(var i = 0; i < 10; i++)
{
methods.push(function() {
require("system").print(i);
});
}
for(var k = 0; k < 10; k++)
{
methods[k]();
}
// prints "10" ten times.
var methods = [];
for(var i = 0; i < 10; i++)
{
(function(){
var x = i;
methods.push(function() {
require("system").print(x);
});
})();
}
for(var k = 0; k < 10; k++)
{
methods[k]();
}
// prints "0,1,2,3,4,5,6,7,8,9"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment