codice:
function Iteration (oCollection) {
this.current = 0;
this.collection = oCollection;
}
Iteration.prototype.next = function (nCurrent) {
return !nCurrent || (this.current = nCurrent), this.collection[this.current++ % this.collection.length];
}
// ........
var foto = [
"images/img_S1_0_0.gif",
"images/img_S1_1_0.gif",
"images/img_S1_1_1.gif",
"images/img_SU_0_0.gif"
];
var collezioneFoto = new Iteration(foto);
alert(collezioneFoto.next());
alert(collezioneFoto.next());
alert(collezioneFoto.next());
// riparto da 1...
alert(collezioneFoto.next(1));
alert(collezioneFoto.next());