forked from robdodson/JavaScript-Design-Patterns
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
35 lines (30 loc) · 752 Bytes
/
main.js
File metadata and controls
35 lines (30 loc) · 752 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
// Examples inspired by Stoyan Stefanov and his
// amazing book JavaScript Patterns
// http://www.amazon.com/JavaScript-Patterns-Stoyan-Stefanov/dp/0596806752
"use strict";
var iterator = (function() {
var index = 0,
data = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
length = data.length;
return {
next: function() {
var element;
if (!this.hasNext()) {
return null;
}
element = data[index];
index += 3;
return element;
},
hasNext: function() {
return index < length;
},
rewind: function() {
index = 0;
return data[index];
},
current: function() {
return data[index];
}
};
}());