UNPKG

1.2 kBJavaScriptView Raw
1import copyObjectWith from './_copyObjectWith';
2import createAssigner from './_createAssigner';
3import keys from './keys';
4
5/**
6 * This method is like `_.assign` except that it accepts `customizer`
7 * which is invoked to produce the assigned values. If `customizer` returns
8 * `undefined`, assignment is handled by the method instead. The `customizer`
9 * is invoked with five arguments: (objValue, srcValue, key, object, source).
10 *
11 * **Note:** This method mutates `object`.
12 *
13 * @static
14 * @memberOf _
15 * @since 4.0.0
16 * @category Object
17 * @param {Object} object The destination object.
18 * @param {...Object} sources The source objects.
19 * @param {Function} [customizer] The function to customize assigned values.
20 * @returns {Object} Returns `object`.
21 * @example
22 *
23 * function customizer(objValue, srcValue) {
24 * return _.isUndefined(objValue) ? srcValue : objValue;
25 * }
26 *
27 * var defaults = _.partialRight(_.assignWith, customizer);
28 *
29 * defaults({ 'a': 1 }, { 'b': 2 }, { 'a': 3 });
30 * // => { 'a': 1, 'b': 2 }
31 */
32var assignWith = createAssigner(function(object, source, srcIndex, customizer) {
33 copyObjectWith(source, keys(source), object, customizer);
34});
35
36export default assignWith;