下面这样也可以,不用 this ,用 iterator 就可以 class makeIterator { constructor(arr) { arr[Symbol.iterator] = function () { let i = 0, j = 0; return { next () { if (i >= arr.length) return { value: undefined, done: true }; let value = arr[i][j]; j++; if (j >= arr[i].length) { i++; j = 0; } return { value, done: false }; } } } this.iterator = arr[Symbol.iterator](); } next () { return this.iterator.next().value } } let m = new makeIterator([[1, 4, 7], [2, 9], [8, 7, 6, 3]]); console.log(m.next()); console.log(m.next()); console.log(m.next()); console.log(m.next()); console.log(m.next()); console.log(m.next()); console.log(m.next()); console.log(m.next());
点赞 评论

相关推荐

小浪_Coding:找硬件测试,也可兼顾软测欧, 简历还可以的 ,注意排版,项目写的有条理一点, 然后个人技能多加点, 润色好简历之后就开始沟通海投了,深圳,东莞这边做硬件相关的公司还不少, 医疗类,仪器类的都可以尝试
点赞 评论 收藏
分享
牛客网
牛客网在线编程
牛客网题解
牛客企业服务