I have this sample code:
function(){
var events = [];
var pages = ["a", "b", "c"];
for(var pageIndex in pages){
var pageName = pages[pageIndex];
var e = function(){
console.info(pageName);
};
events.push(e);
}
for(var eventIndex in events){
console.info("index: " + eventIndex);
events[eventIndex]();
}
}
Output:
index: 0
c
index: 1
c
index: 2
c
Desired output:
index: 0
a
index: 1
b
index: 2
c
Is there a standard practice for this?