I want to define an array of function so I tried the following code, but it does not has the intended result, because the i in the loop cannot be retrieved else where.
<script>
var f = []
for (var i=0; i<1000; i++){
f[i] = function(){
return i
}
}
console.log(f[3]);
</script>
There is the brute-force method to write 1000 lines of codes to define function, is there other ways? In fact I met this problem in Java, Array of function pointers in Java , so answers in both Java or JS would be helpful.