defaults.js 1013 B

1234567891011121314151617181920212223242526272829303132
  1. var apply = require('./_apply'),
  2. assignInDefaults = require('./_assignInDefaults'),
  3. assignInWith = require('./assignInWith'),
  4. baseRest = require('./_baseRest');
  5. /**
  6. * Assigns own and inherited enumerable string keyed properties of source
  7. * objects to the destination object for all destination properties that
  8. * resolve to `undefined`. Source objects are applied from left to right.
  9. * Once a property is set, additional values of the same property are ignored.
  10. *
  11. * **Note:** This method mutates `object`.
  12. *
  13. * @static
  14. * @since 0.1.0
  15. * @memberOf _
  16. * @category Object
  17. * @param {Object} object The destination object.
  18. * @param {...Object} [sources] The source objects.
  19. * @returns {Object} Returns `object`.
  20. * @see _.defaultsDeep
  21. * @example
  22. *
  23. * _.defaults({ 'a': 1 }, { 'b': 2 }, { 'a': 3 });
  24. * // => { 'a': 1, 'b': 2 }
  25. */
  26. var defaults = baseRest(function(args) {
  27. args.push(undefined, assignInDefaults);
  28. return apply(assignInWith, undefined, args);
  29. });
  30. module.exports = defaults;