compose.js 454 B

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