. , , , , , .
:
function flow(funcArr, funcDone) {
function proceed(i) {
if (i < funcArr.length) {
return function() {
funcArr[i](proceed(i+1));
}
} else {
return funcDone;
}
}
proceed(0)();
}
: . .
: proceed(i) , th ( funcDone, ). proceed(i) , , proceed(i+1) contiunation.
:
flow([
function(cb) { print("Thing one"); cb(); },
function(cb) { print("Thing two"); cb(); },
function(cb) { print("Thing three"); cb(); },
function(cb) { print("Thing four"); cb(); },
], function() {
print("Done.");
});
cb();. , , , , . : cb, , .
, : ( ) JavaScript . funcArr , . , JavaScript.