Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
80742 views
1
var assign = require('./assign'),
2
assignDefaults = require('../internal/assignDefaults'),
3
restParam = require('../function/restParam');
4
5
/**
6
* Assigns own enumerable properties of source object(s) to the destination
7
* object for all destination properties that resolve to `undefined`. Once a
8
* property is set, additional values of the same property are ignored.
9
*
10
* **Note:** This method mutates `object`.
11
*
12
* @static
13
* @memberOf _
14
* @category Object
15
* @param {Object} object The destination object.
16
* @param {...Object} [sources] The source objects.
17
* @returns {Object} Returns `object`.
18
* @example
19
*
20
* _.defaults({ 'user': 'barney' }, { 'age': 36 }, { 'user': 'fred' });
21
* // => { 'user': 'barney', 'age': 36 }
22
*/
23
var defaults = restParam(function(args) {
24
var object = args[0];
25
if (object == null) {
26
return object;
27
}
28
args.push(assignDefaults);
29
return assign.apply(undefined, args);
30
});
31
32
module.exports = defaults;
33
34