Ohm-Management - Projektarbeit B-ME
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

_createRecurry.js 2.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. var isLaziable = require('./_isLaziable'),
  2. setData = require('./_setData'),
  3. setWrapToString = require('./_setWrapToString');
  4. /** Used to compose bitmasks for function metadata. */
  5. var WRAP_BIND_FLAG = 1,
  6. WRAP_BIND_KEY_FLAG = 2,
  7. WRAP_CURRY_BOUND_FLAG = 4,
  8. WRAP_CURRY_FLAG = 8,
  9. WRAP_PARTIAL_FLAG = 32,
  10. WRAP_PARTIAL_RIGHT_FLAG = 64;
  11. /**
  12. * Creates a function that wraps `func` to continue currying.
  13. *
  14. * @private
  15. * @param {Function} func The function to wrap.
  16. * @param {number} bitmask The bitmask flags. See `createWrap` for more details.
  17. * @param {Function} wrapFunc The function to create the `func` wrapper.
  18. * @param {*} placeholder The placeholder value.
  19. * @param {*} [thisArg] The `this` binding of `func`.
  20. * @param {Array} [partials] The arguments to prepend to those provided to
  21. * the new function.
  22. * @param {Array} [holders] The `partials` placeholder indexes.
  23. * @param {Array} [argPos] The argument positions of the new function.
  24. * @param {number} [ary] The arity cap of `func`.
  25. * @param {number} [arity] The arity of `func`.
  26. * @returns {Function} Returns the new wrapped function.
  27. */
  28. function createRecurry(func, bitmask, wrapFunc, placeholder, thisArg, partials, holders, argPos, ary, arity) {
  29. var isCurry = bitmask & WRAP_CURRY_FLAG,
  30. newHolders = isCurry ? holders : undefined,
  31. newHoldersRight = isCurry ? undefined : holders,
  32. newPartials = isCurry ? partials : undefined,
  33. newPartialsRight = isCurry ? undefined : partials;
  34. bitmask |= (isCurry ? WRAP_PARTIAL_FLAG : WRAP_PARTIAL_RIGHT_FLAG);
  35. bitmask &= ~(isCurry ? WRAP_PARTIAL_RIGHT_FLAG : WRAP_PARTIAL_FLAG);
  36. if (!(bitmask & WRAP_CURRY_BOUND_FLAG)) {
  37. bitmask &= ~(WRAP_BIND_FLAG | WRAP_BIND_KEY_FLAG);
  38. }
  39. var newData = [
  40. func, bitmask, thisArg, newPartials, newHolders, newPartialsRight,
  41. newHoldersRight, argPos, ary, arity
  42. ];
  43. var result = wrapFunc.apply(undefined, newData);
  44. if (isLaziable(func)) {
  45. setData(result, newData);
  46. }
  47. result.placeholder = placeholder;
  48. return setWrapToString(result, func, bitmask);
  49. }
  50. module.exports = createRecurry;