All files / src/helpers deepExtend.js

100% Statements 1/1
100% Branches 0/0
100% Functions 0/0
100% Lines 1/1
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39                                                                    1x        
import extend from './extend'
/**
 * A more semantic convenience function. Delegates to {@link extend} and passes `true` as the first argument. Deep merge the contents of two or more objects together into the first object.
 *
 * @function deepExtend
 * @param {Object} destination The object to modify
 * @param {Object} source The object whose keys to take
 * @param {Object} [source2] Optional, You can add any number of objects as arguments.
 * @returns {Object} result The merged object. Note that the `destination` object will always be modified.
 *
 * @example
 * var object1 = {
 *   apple: 0,
 *   banana: { weight: 52, price: 100 },
 *   cherry: 97
 * }
 * var object2 = {
 *   banana: { price: 200 },
 *   almond: 100
 * }
 * io.deepExtend(object1, object2)
 * console.log(object1)
 * //  {
 * //   apple: 0,
 * //   banana: {
 * //     weight: 52,
 * //     price: 200
 * //   },
 * //   cherry: 97,
 * //   almond: 100
 * // }
 *
 */
export default function deepExtend () {
  var args = Array.prototype.slice.call(arguments) // Make real array from arguments
  args.unshift(true) // Add `true` as first arg.
  extend.apply(this, args)
}