this function dim is intended to create an array of specific length (d), incrementing by 1 from a specific digital (n).
question 1: why is the first bit of the returned array always the parameter passed in at the beginning? Shouldn"t I PP?
question 2: I don"t quite understand the concept of closure. Please explain why adding n parameters to the function in line 6 and 7 will cause an exception (I think the parameter should be imported into the following parameter)
for example, if I pass n into the function in the sixth line, he won"t start to increase according to the number I specified. Instead,
with a return value starting from 0: (10) [0,1,2,3,4,5,6,7,8,9]
function ontology:
Array.dim = function(d, n){
var i,
a = []
//n = n + 1;
for (i = 0; i < d; iPP){
a[i] = (function (){ //n
return function(){ //n
return nPP
}()
})(i)
}
return a
}
var arr = Array.dim(10,2);
console.log(arr) //(10)[2, 3, 4, 5, 6, 7, 8, 9, 10, 11]