| 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 | 1 1 1 1 3 3 6 3 1 | define(function () {
/**
* Returns a function that composes multiple functions, passing results to
* each other.
* @version 0.1.0 (2012/05/24)
*/
function compose() {
var fns = arguments;
return function(arg){
// only cares about the first argument since the chain can only
// deal with a single return value anyway. It should start from
// the last fn.
var n = fns.length;
while (n--) {
arg = fns[n].call(this, arg);
}
return arg;
};
}
return compose;
});
|