Runs an array of functions in series, each passing their results to the next in the array and all of them can have initial context. However, this piece of code not handle errors. So if any of functions throw error it is thrown directly. lol.
If you want something more robust so you should try
http://npm.im/catchy - very similar, but plays like promises - with context, resolve and reject.
function awf(n,t,l){!function c(){t.length>0?t.shift().apply(n||{},[].slice.call(arguments).concat(c)):0,0==t.length?l.call(n):0}()}
awf({
foo: 'bar',
baz: 1
}, [
function step1(next) {
console.log('step1');
next();
},
function step2(next) {
console.log('step2');
console.log('increment baz with 100');
this.baz += 100;
next(this.baz);
},
function step3(baz, next) {
var self = this;
console.log('step3');
console.log('baz is ' + baz);
self.foo = 'foo_step3'
console.log('foo changed to ' + self.foo);
setTimeout(function() {
console.log('step3:setTimeout');
console.log('increment baz with 200');
self.baz += 200;
next(self.baz);
}, 500);
},
function step4(baz301, next) {
console.log('step4');
console.log('context object is ' + JSON.stringify(this, null, 2));
console.log('baz is 301: ' + baz301)
},
], function done() {
console.log('done');
});