Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
80742 views
1
var assignWith = require('../internal/assignWith'),
2
baseAssign = require('../internal/baseAssign'),
3
createAssigner = require('../internal/createAssigner');
4
5
/**
6
* Assigns own enumerable properties of source object(s) to the destination
7
* object. Subsequent sources overwrite property assignments of previous sources.
8
* If `customizer` is provided it is invoked to produce the assigned values.
9
* The `customizer` is bound to `thisArg` and invoked with five arguments:
10
* (objectValue, sourceValue, key, object, source).
11
*
12
* **Note:** This method mutates `object` and is based on
13
* [`Object.assign`](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-object.assign).
14
*
15
* @static
16
* @memberOf _
17
* @alias extend
18
* @category Object
19
* @param {Object} object The destination object.
20
* @param {...Object} [sources] The source objects.
21
* @param {Function} [customizer] The function to customize assigned values.
22
* @param {*} [thisArg] The `this` binding of `customizer`.
23
* @returns {Object} Returns `object`.
24
* @example
25
*
26
* _.assign({ 'user': 'barney' }, { 'age': 40 }, { 'user': 'fred' });
27
* // => { 'user': 'fred', 'age': 40 }
28
*
29
* // using a customizer callback
30
* var defaults = _.partialRight(_.assign, function(value, other) {
31
* return _.isUndefined(value) ? other : value;
32
* });
33
*
34
* defaults({ 'user': 'barney' }, { 'age': 36 }, { 'user': 'fred' });
35
* // => { 'user': 'barney', 'age': 36 }
36
*/
37
var assign = createAssigner(function(object, source, customizer) {
38
return customizer
39
? assignWith(object, source, customizer)
40
: baseAssign(object, source);
41
});
42
43
module.exports = assign;
44
45