Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

assignWith.js 1.2KB

12345678910111213141516171819202122232425262728293031323334353637
  1. var copyObject = require('./_copyObject'),
  2. createAssigner = require('./_createAssigner'),
  3. keys = require('./keys');
  4. /**
  5. * This method is like `_.assign` except that it accepts `customizer`
  6. * which is invoked to produce the assigned values. If `customizer` returns
  7. * `undefined`, assignment is handled by the method instead. The `customizer`
  8. * is invoked with five arguments: (objValue, srcValue, key, object, source).
  9. *
  10. * **Note:** This method mutates `object`.
  11. *
  12. * @static
  13. * @memberOf _
  14. * @since 4.0.0
  15. * @category Object
  16. * @param {Object} object The destination object.
  17. * @param {...Object} sources The source objects.
  18. * @param {Function} [customizer] The function to customize assigned values.
  19. * @returns {Object} Returns `object`.
  20. * @see _.assignInWith
  21. * @example
  22. *
  23. * function customizer(objValue, srcValue) {
  24. * return _.isUndefined(objValue) ? srcValue : objValue;
  25. * }
  26. *
  27. * var defaults = _.partialRight(_.assignWith, customizer);
  28. *
  29. * defaults({ 'a': 1 }, { 'b': 2 }, { 'a': 3 });
  30. * // => { 'a': 1, 'b': 2 }
  31. */
  32. var assignWith = createAssigner(function(object, source, srcIndex, customizer) {
  33. copyObject(source, keys(source), object, customizer);
  34. });
  35. module.exports = assignWith;