-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfi.js
More file actions
73 lines (59 loc) · 1.46 KB
/
Copy pathfi.js
File metadata and controls
73 lines (59 loc) · 1.46 KB
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
(function() {
var root = this;
var fi = {};
if (typeof exports !== 'undefined') {
if (typeof module !== 'undefined' && module.exports) {
exports = module.exports = fi;
}
exports.fi = fi;
} else {
root.fi = fi;
}
var iterify = fi.iterify = function(array) {
var index = 0;
var length = array.length;
var iter = function() {
return (index < length) ? array[index++] : void 0;
}
return iter
}
var willClone = fi.willClone = function(itrable) {
if (itrable instanceof willClone) return itrable;
if (!(this instanceof willClone)) return new willClone(itrable);
this.iterable = itrable;
this.clone = [];
};
willClone.prototype.getClone = function() {
var _this = this;
var index = 0;
var iter = function() {
var result;
if (index < _this.clone.length) {
result = _this.clone[index];
} else {
result = _this.iterable()
if (result !== undefined) {
_this.clone[index] = result;
}
}
++index;
return result;
}
return iter
};
// arr = [1, 2, 3]
// iter = iterify(arr)
// cloneStation = willClone(iter)
// clone = cloneStation.getClone()
// while (obj = clone()) {
// console.log(obj)
// }
// clone = cloneStation.getClone()
// while (obj = clone()) {
// console.log(obj)
// }
// clone = cloneStation.getClone()
// while (obj = clone()) {
// console.log(obj)
// }
}).call(this);