手写个简单的遍历器

Array.prototype.values = function(){
let i = 0;
let self = this
return {
next(){
const done = i>= self.length
const value = done? undefined : self[i++]
return {
value,
done
}
}
}
}
const color = ['red','green','white'];
//控制台
color.values()
color.next()
输出……xxx  自己尝试一下把

猜你喜欢

转载自www.cnblogs.com/jwzhang/p/12105160.html