Skip to content

Instantly share code, notes, and snippets.

@rochnyak-d-i
Created October 28, 2014 05:02
Show Gist options
  • Save rochnyak-d-i/7af3bb2029c4d4a4544f to your computer and use it in GitHub Desktop.
Save rochnyak-d-i/7af3bb2029c4d4a4544f to your computer and use it in GitHub Desktop.
JS шаблон итератор
var agg = (function () {
var index = 0,
data = [1, 2, 3, 4, 5],
length = data.length;
return {
next:function () {
var element;
if (!this.hasNext()) {
return null;
}
element = data[index];
index = index + 2;
return element;
},
hasNext:function () {
return index < length;
},
rewind:function () {
index = 0;
},
current:function () {
return data[index];
}
};
}());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment