I am creating a class to practice iterators in javascript. This is my code:
class iterador{
constructor(...n){
this.n = n
this.lon = n.length
this.indice = 0
this.next = function next(){
return this.indice < this.lon ? {value:this.n[this.indice++], done: false} : {done:true}
}
}
loop(){
let l = {}
l[Symbol.iterator] = this.next
console.log(l)
let i = 0
for(let value of l){
console.log(value)
i++
if(i>this.lon) break
}
}
}
const ite = new iterador(1,2,3,4,5,6,7,8,9,10)
ite.next().value // 1
ite.loop() // no funciona
The idea is that the loop () method gives me a tour of all the parameters that I sent when creating the new object ite, some advice?