Is storing array values inside of a closure considered to be bad practice? I having been trying to decide if I should just use a standard object with key value pair. This is not the method I am using to populate arrays, but this does show how i create functions to store values.
Also, I'm wondering if this is technically a closure.
http://jsfiddle.net/canoeBoy/sn3wgs0w/
<input type="button" onclick="alert(Test1(0,0,'array'));
alert(Test2(0,0,'array'));
alert(Test3(0,0,'array'));">
function makeClosures(){
var nameArr=["Test1","Test2","Test3","Test4","Test5","Test6","Test7"];
for(var i=0;i<nameArr.length;i+=1){
var nam=nameArr[i];
window[nam]=funcsRun(nam,0,1);
}
}
function funcsRun(nam,index,action){
var a=nam;
var arr=[];
return function(value,index,action) {
if(action=='array'){
}
else if(action=='copyEntireArray'){
arr=value;
}
else if(action=='resetArray'){
arr=[];
}
else if(action=='copyToIndex'){
arr[index]=value;
}
else if(action=='indexValue'){
return arr[index];
}
else if(action=='push'){
arr.push(value);
}
return arr;
};
};
makeClosures();
for(i=0;i<100;i+=1){
Test1(Math.floor((Math.random() * 100) + 1),i,'copyToIndex');
Test2(Math.floor((Math.random() * 100) + 1),i,'copyToIndex');
Test3(Math.floor((Math.random() * 100) + 1),i,'copyToIndex');
}