1 var baseClone = require('../internal/baseClone'),
2 bindCallback = require('../internal/bindCallback');
5 * Creates a deep clone of `value`. If `customizer` is provided it's invoked
6 * to produce the cloned values. If `customizer` returns `undefined` cloning
7 * is handled by the method instead. The `customizer` is bound to `thisArg`
8 * and invoked with up to three argument; (value [, index|key, object]).
10 * **Note:** This method is loosely based on the
11 * [structured clone algorithm](http://www.w3.org/TR/html5/infrastructure.html#internal-structured-cloning-algorithm).
12 * The enumerable properties of `arguments` objects and objects created by
13 * constructors other than `Object` are cloned to plain `Object` objects. An
14 * empty object is returned for uncloneable values such as functions, DOM nodes,
15 * Maps, Sets, and WeakMaps.
20 * @param {*} value The value to deep clone.
21 * @param {Function} [customizer] The function to customize cloning values.
22 * @param {*} [thisArg] The `this` binding of `customizer`.
23 * @returns {*} Returns the deep cloned value.
27 * { 'user': 'barney' },
31 * var deep = _.cloneDeep(users);
32 * deep[0] === users[0];
35 * // using a customizer callback
36 * var el = _.cloneDeep(document.body, function(value) {
37 * if (_.isElement(value)) {
38 * return value.cloneNode(true);
42 * el === document.body
46 * el.childNodes.length;
49 function cloneDeep(value, customizer, thisArg) {
50 return typeof customizer == 'function'
51 ? baseClone(value, true, bindCallback(customizer, thisArg, 3))
52 : baseClone(value, true);
55 module.exports = cloneDeep;