-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfunctionSeries.js
More file actions
38 lines (37 loc) · 876 Bytes
/
functionSeries.js
File metadata and controls
38 lines (37 loc) · 876 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
36
37
38
var series = function(functions, callback) {
var functionIndex = 0;
var next = function() {
functionIndex++;
if (functionIndex < functions.length) {
functions[functionIndex].call(functions[functionIndex], next);
} else {
if (typeof callback === 'function') {
callback();
}
}
};
for (var i in functions) {
functions[i].bind(functions[i], next);
}
functions[functionIndex].call(functions[functionIndex], next);
};
series([
function(next) {
console.log('function 1 called');
next();
},
function(next) {
window.setTimeout(function() {
console.log('function 2 called');
next();
}, 1000);
},
function(next) {
window.setTimeout(function() {
console.log('function 3 called');
next();
}, 1000);
}
], function() {
alert('all functions complete');
});