merge.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. var baseMerge = require('./_baseMerge'),
  2. createAssigner = require('./_createAssigner');
  3. /**
  4. * This method is like `_.assign` except that it recursively merges own and
  5. * inherited enumerable string keyed properties of source objects into the
  6. * destination object. Source properties that resolve to `undefined` are
  7. * skipped if a destination value exists. Array and plain object properties
  8. * are merged recursively. Other objects and value types are overridden by
  9. * assignment. Source objects are applied from left to right. Subsequent
  10. * sources overwrite property assignments of previous sources.
  11. *
  12. * **Note:** This method mutates `object`.
  13. *
  14. * @static
  15. * @memberOf _
  16. * @since 0.5.0
  17. * @category Object
  18. * @param {Object} object The destination object.
  19. * @param {...Object} [sources] The source objects.
  20. * @returns {Object} Returns `object`.
  21. * @example
  22. *
  23. * var object = {
  24. * 'a': [{ 'b': 2 }, { 'd': 4 }]
  25. * };
  26. *
  27. * var other = {
  28. * 'a': [{ 'c': 3 }, { 'e': 5 }]
  29. * };
  30. *
  31. * _.merge(object, other);
  32. * // => { 'a': [{ 'b': 2, 'c': 3 }, { 'd': 4, 'e': 5 }] }
  33. */
  34. var merge = createAssigner(function(object, source, srcIndex) {
  35. baseMerge(object, source, srcIndex);
  36. });
  37. module.exports = merge;