반응형
function iterator(collection) {
var index = 0;
var length = collection.length;
function next() {
var item = collection[index++];
next.hasNext = index < length;
return item;
}
next.hasNext = index < length;
return next;
}
(function () {
var collection = [1, 2, 3, 4, 5];
var next = iterator(collection);
var result = [];
while (next.hasNext) {
result.push(next());
}
console.log(collection);
console.log(result);
}());
반응형
'etc' 카테고리의 다른 글
memoize (0) | 2011.10.05 |
---|---|
Adding event handlers (0) | 2011.10.05 |
add select option (0) | 2011.09.07 |
[JS] click event (0) | 2011.09.07 |
SMDIC, document image generator (0) | 2011.09.05 |