const banji = {
cname: "yiban",
stus: ["stuA", "stuB", "stuC", "stuD", "stuE"],
[Symbol.iterator]() {
let index = 0;
return {
next: () => {
if (index < this.stus.length) {
const result = { value: this.stus[index], done: false };
index++;
return result;
} else {
return { value: undefined, done: true };
}
},
};
},
};
for (let i of banji) {
console.log(i);
}
es6迭代器Symbol.iterator
最新推荐文章于 2024-07-19 00:10:41 发布