compose.js 411 B

123456789101112131415
  1. // Returns a function that is the composition of a list of functions, each
  2. // consuming the return value of the function that follows.
  3. function compose() {
  4. var args = arguments;
  5. var start = args.length - 1;
  6. return function() {
  7. var i = start;
  8. var result = args[start].apply(this, arguments);
  9. while (i--) result = args[i].call(this, result);
  10. return result;
  11. };
  12. }
  13. module.exports = compose;