class List{
constructor(){
this.data = [1,2,3];
}
[Symbol.iterator](){
return this.data;
}
}
let list = new List();
for(let i of list)
console.log(i);
Error in the for() line:
Uncaught TypeError: undefined is not a function
So it's not possible to use iterator with our own classes like in PHP?
return this.data[Symbol.iterator]()*[Symbol.iterator](){ for(let i of this.data) yield i; }