Just because functions are first class objects, there are closures, and higher order functions, does Javascript deserve to be called a Functional Programming language? The
@petraszd I rewrite your code a little to obtain a "new" for operator:
function ffor(a, b, f){
function it(i){
if(i > b)return
f(i)
it(i+1)
}
it(a)
}
print("----" + new Date()+"----")
var funcs = []
ffor(0, 9, function(i){
funcs.push(function(){return i})
})
ffor(0, 9, function(i){
print(funcs[i]())
})
But I know that this way has disadvantages for big loops...
Related question about tail recurtion optimization in JS
P.S. Posted here cuz have problem with code formatting while posting as comment