Skip to content

Commit f789eeb

Browse files
committed
Resolved merge conflict
1 parent d9db10a commit f789eeb

File tree

1 file changed

+56
-69
lines changed

1 file changed

+56
-69
lines changed

‎design-patterns/iterator.html‎

Lines changed: 56 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -1,71 +1,58 @@
11
<!doctype html>
22
<htmllang="en">
3-
<head>
4-
<title>JavaScript Patterns</title>
5-
<metacharset="utf-8">
6-
</head>
7-
<body>
8-
<script>
9-
/* Title: Iterator
10-
Description: implements a specialized language
11-
*/
12-
13-
varelement;
14-
while(element=agg.next()){
15-
// do something with the element
16-
console.log(element);
17-
}
18-
19-
while(agg.hasNext()){
20-
// do something with the next element...
21-
console.log(agg.next());
22-
}
23-
24-
varagg=(function(){
25-
26-
varindex=0,
27-
data=[1,2,3,4,5],
28-
length=data.length;
29-
30-
return{
31-
32-
next:function(){
33-
varelement;
34-
if(!this.hasNext()){
35-
returnnull;
36-
}
37-
element=data[index];
38-
index=index+2;
39-
returnelement;
40-
},
41-
42-
hasNext:function(){
43-
returnindex<length;
44-
},
45-
46-
rewind:function(){
47-
index=0;
48-
},
49-
50-
current:function(){
51-
returndata[index];
52-
}
53-
54-
};
55-
}());
56-
57-
// this loop logs 1, then 3, then 5
58-
while(agg.hasNext()){
59-
console.log(agg.next());
60-
}
61-
62-
// go back
63-
agg.rewind();
64-
console.log(agg.current());// 1
65-
66-
// reference
67-
// http://www.addyosmani.com/resources/essentialjsdesignpatterns/book/#iteratorpatternjquery
68-
// http://shop.oreilly.com/product/9780596806767.do?sortby=publicationDate
69-
</script>
70-
</body>
71-
</html>
3+
<head>
4+
<title>JavaScript Patterns</title>
5+
<metacharset="utf-8">
6+
</head>
7+
<body>
8+
<script>
9+
/* Title: Iterator
10+
Description: implements a specialized language
11+
*/
12+
varelement;
13+
while(element-agg.next()){
14+
// do something with the element
15+
console.log(element);
16+
}
17+
while(agg.hasNext()){
18+
// do something with the next element...
19+
console.log(agg.next());
20+
}
21+
varagg=(function(){
22+
varindex=0,
23+
data=[1,2,3,4,5],
24+
length=data.length;
25+
return{
26+
next:function(){
27+
varelement;
28+
if(!this.hasNext()){
29+
returnnull;
30+
}
31+
element=data[index];
32+
index=index+2;
33+
returnelement;
34+
},
35+
hasNext:function(){
36+
returnindex<length;
37+
},
38+
rewind:function(){
39+
index=0;
40+
},
41+
current:function(){
42+
returndata[index];
43+
}
44+
};
45+
}());
46+
// this loop logs 1, then 3, then 5
47+
while(agg.hasNext()){
48+
console.log(agg.next());
49+
}
50+
// go back
51+
agg.rewind();
52+
console.log(agg.current());// 1
53+
// reference
54+
// http://www.addyosmani.com/resources/essentialjsdesignpatterns/book/#iteratorpatternjquery
55+
// http://shop.oreilly.com/product/9780596806767.do?sortby=publicationDate
56+
</script>
57+
</body>
58+
</html>

0 commit comments

Comments
(0)