Pipeline
charlesfeng
1 Likes0 CommentsjavascriptPipeline.prototype.exec = function () { var fns = this.fns.slice(0); var args = Array.prototype.slice.call(arguments, 0); var done = args.length && typeof args[args.length - 1] === 'function' ? args.pop() : function () {}; if (!args.length && fns.length && fns[0].length > 1) { args.push({}); while (args.length < fns[0].length - 1) { args.push(null); } } var next = function (err) { if (!err && fns.length) { fns.shift().apply(null, args.concat([next])); } else { done.apply(null, [err].concat(args)); } }; setTimeout(next, 0); return this; };