assignWith.js 938 B

1234567891011121314151617181920212223242526272829303132
  1. import keys from '../object/keys';
  2. /**
  3. * A specialized version of `_.assign` for customizing assigned values without
  4. * support for argument juggling, multiple sources, and `this` binding `customizer`
  5. * functions.
  6. *
  7. * @private
  8. * @param {Object} object The destination object.
  9. * @param {Object} source The source object.
  10. * @param {Function} customizer The function to customize assigned values.
  11. * @returns {Object} Returns `object`.
  12. */
  13. function assignWith(object, source, customizer) {
  14. var index = -1,
  15. props = keys(source),
  16. length = props.length;
  17. while (++index < length) {
  18. var key = props[index],
  19. value = object[key],
  20. result = customizer(value, source[key], key, object, source);
  21. if ((result === result ? (result !== value) : (value === value)) ||
  22. (value === undefined && !(key in object))) {
  23. object[key] = result;
  24. }
  25. }
  26. return object;
  27. }
  28. export default assignWith;