手写个简单的Array.prototype.values()遍历器

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  自己尝试一下把

 

……

posted @ 2019-12-26 23:41  问问大将军  阅读(140)  评论(0编辑  收藏  举报