From JavaScript Iterators
var Iterator = function(arr){ return {
index : -1,
hasNext : function(){ return this.index <= arr.length; },
hasPrevious: function(){ return this.index > 0; },
current: function(){ return arr[ this["index"] ]; },
next : function(){
if(this.hasNext()){
this.index = this.index + 1;
return this.current();
}
return false;
},
previous : function(){
if(this.hasPrevious()){
this.index = this.index - 1
return this.current();
}
return false;
}
}
};
var iter = Iterator([1,2,3]);
I want to rewrite this functionality through the addition of dynamic values
added : function(data){
arr.push(data);
this.index++
}
iter.added(1);
iter.added(6);
iter.added(7);
iter.added(8);
How do it ? I knows about iterator in ES 6 https://developer.mozilla.org/ru/docs/Web/JavaScript/Reference/Global_Objects/Iterator but i want support IE