Prechádza prvky kolekcie bez toho, aby odhalil jej vnútornú stavbu.
class ListIterator { constructor(items) { this.items = items; this.position = 0; } hasNext() { return this.position < this.items.length; } next() { const item = this.items[this.position]; this.position += 1; return item; }} class ItemList { #items = []; add(item) { this.#items.push(item); } iterator() { return new ListIterator(this.#items); }} const it = list.iterator();while (it.hasNext()) { process(it.next()); // the client has no idea what is inside the list}