//声明一个对象 const banji = { name: "一班", stus: [ "xiaobai", "xiaohei", "xiaohua", "king" ], [Symbol.iterator]() { //声明索引变量 let index = 0; let _this = this; return { next: function() { if (index < _this.stus.length) { const result = { value: _this.stus[index], done: false }; index++; return result; } else { return { value: undefined, done: true } } } } } } //遍历这个对象 for (const v of banji) { console.log(v); }
标签:ES6,遍历,return,自定义,迭代,index,stus,const From: https://www.cnblogs.com/xiaobaizitaibai/p/16813699.html