I am trying to create a array made up by function in JavaScript. I writed the following code to ensure each function in the array return it position, but I get 10 for every function in the array,can any one explain why?
function createFunctionArray(){
var result = new Array();
for(i=0;i<10;++i){
result[i] = function(){
var now = i;
return now;
};
}
return result
}