generator不怎么常用,有更好的轻喷。 Array.prototype.getReader2 = function () { let arr = this; function * name (len) { let index = 0; while (index < arr.length) { let end = index + len; len = yield arr.slice(index, end); index = end; } } let it; return { read (num = 1) { if (!it) { it = name(num); } let { value , done } = it.next(num); return done ? [] : value; } } }
点赞 评论

相关推荐

牛至超人:您好,京东物流岗了解一下吗?负责精加工食品的端到端传输
点赞 评论 收藏
分享
牛客网
牛客网在线编程
牛客网题解
牛客企业服务