Symbol.iterator

2021-12-08  本文已影响0人  纱云

const obj = {
store:['foo','bar','gba'],
[Symbol.iterator]:function(){
let index = 0
const self = this
return{
next:function(){
const result = {
value:self.store[index],
done:index>=self.store.length
}
index++
return result;
}
}
}
}
for(const item of obj){
console.log(item);
}

上一篇 下一篇

猜你喜欢

热点阅读