loading
open in
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
class Document{
	constructor(content){
		this.content = content;
	}

	[Symbol.iterator](){
	  let index = 0;
	  let words = this.content.split(" ");
	   return{
	     next: ()=>{
	       let currentValue = words[index++];
	       return {value:currentValue, done:index > words.length};
	     }
	   }
  }
}
let doc = new Document("Hola mundo como estas");

for(let word of doc) {console.log(word); }
Native Browser JavaScript