1var funcs = [];
2
3function createfunc(i) {
4 return function() {
5 console.log("My value: " + i);
6 };
7}
8
9for (var i = 0; i < 3; i++) {
10 funcs[i] = createfunc(i);
11}
12
13for (var j = 0; j < 3; j++) {
14 // and now let's run each one to see
15 funcs[j]();
16}