_createOver.js 780 B

12345678910111213141516171819202122232425262728
  1. var apply = require('./_apply'),
  2. arrayMap = require('./_arrayMap'),
  3. baseIteratee = require('./_baseIteratee'),
  4. baseRest = require('./_baseRest'),
  5. baseUnary = require('./_baseUnary'),
  6. flatRest = require('./_flatRest');
  7. /**
  8. * Creates a function like `_.over`.
  9. *
  10. * @private
  11. * @param {Function} arrayFunc The function to iterate over iteratees.
  12. * @returns {Function} Returns the new over function.
  13. */
  14. function createOver(arrayFunc) {
  15. return flatRest(function(iteratees) {
  16. iteratees = arrayMap(iteratees, baseUnary(baseIteratee));
  17. return baseRest(function(args) {
  18. var thisArg = this;
  19. return arrayFunc(iteratees, function(iteratee) {
  20. return apply(iteratee, thisArg, args);
  21. });
  22. });
  23. });
  24. }
  25. module.exports = createOver;