compose.js 575 B

1234567891011121314151617181920212223
  1. /**
  2. * Returns a function that composes multiple functions, passing results to
  3. * each other.
  4. */
  5. function compose() {
  6. var fns = arguments;
  7. return function(arg){
  8. // only cares about the first argument since the chain can only
  9. // deal with a single return value anyway. It should start from
  10. // the last fn.
  11. var n = fns.length;
  12. while (n--) {
  13. arg = fns[n].call(this, arg);
  14. }
  15. return arg;
  16. };
  17. }
  18. module.exports = compose;