function ge(){
let arr = [1, 2];
let i = 0;
return {
next(){
let done = (i >= arr.length);
let value = !done ? arr[i++] : undefined
return {
done: done,
value: value
}
}
}
}
console.log(ge().next()); //{false, 1}
console.log(ge().next()); //{false, 2}
console.log(ge().next()); //{true, undefined}
网友评论