我不明白的功能fromToFn(), 在我的例子中沒有與該名稱的功能,我不明白的功能
我不明白我的例子
例子:
var fromTo = function fromTo(i,limit){
return function(){
var next = i;
if(i<limit){
i += 1;
return next;
}
return undefined;
}
}
var collect = function collect(fromToFn,array){
return function(){
var value = fromToFn();
if (value !== undefined){
array.push(value);
}
return value;
}
}
var array = [];
var col = collect(fromTo(0,2),array);
col(); //returns 0
col(); //returns 1
col(); //returns undefined
console.log(array); //returns [0,1]
@ T.J.Crowder ok對不起 – hubman