UNPKG

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