partial.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. var createPartial = require('../internal/createPartial');
  2. /** Used to compose bitmasks for wrapper metadata. */
  3. var PARTIAL_FLAG = 32;
  4. /**
  5. * Creates a function that invokes `func` with `partial` arguments prepended
  6. * to those provided to the new function. This method is like `_.bind` except
  7. * it does **not** alter the `this` binding.
  8. *
  9. * The `_.partial.placeholder` value, which defaults to `_` in monolithic
  10. * builds, may be used as a placeholder for partially applied arguments.
  11. *
  12. * **Note:** This method does not set the "length" property of partially
  13. * applied functions.
  14. *
  15. * @static
  16. * @memberOf _
  17. * @category Function
  18. * @param {Function} func The function to partially apply arguments to.
  19. * @param {...*} [partials] The arguments to be partially applied.
  20. * @returns {Function} Returns the new partially applied function.
  21. * @example
  22. *
  23. * var greet = function(greeting, name) {
  24. * return greeting + ' ' + name;
  25. * };
  26. *
  27. * var sayHelloTo = _.partial(greet, 'hello');
  28. * sayHelloTo('fred');
  29. * // => 'hello fred'
  30. *
  31. * // using placeholders
  32. * var greetFred = _.partial(greet, _, 'fred');
  33. * greetFred('hi');
  34. * // => 'hi fred'
  35. */
  36. var partial = createPartial(PARTIAL_FLAG);
  37. // Assign default placeholders.
  38. partial.placeholder = {};
  39. module.exports = partial;