class Comment {
constructor(content, children){
this.children = children;
this.content = content;
}
*[Symbol.iterator](){
yield this.content;
for (let child of this.children){
yield* child;
}
}
}
const children = [
new Comment('good content', []),
new Comment('bad comment', []),
new Comment('hey this has children', [ new Comment('child', [])])
];
const tree = new Comment('Great Post', children);
const values = [];
for (let value of tree){
values.push(value);
}
console.log(values);