码迷,mamicode.com
首页 > 其他好文 > 详细

手写个简单的遍历器

时间:2019-12-27 00:17:40      阅读:72      评论:0      收藏:0      [点我收藏+]

标签:color   sel   white   one   pre   简单   length   class   手写   

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

手写个简单的遍历器

标签:color   sel   white   one   pre   简单   length   class   手写   

原文地址:https://www.cnblogs.com/jwzhang/p/12105160.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!