Initial commit
[yaffs-website] / node_modules / grunt-contrib-watch / node_modules / lodash / lang / cloneDeep.js
1 var baseClone = require('../internal/baseClone'),
2     bindCallback = require('../internal/bindCallback');
3
4 /**
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]).
9  *
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.
16  *
17  * @static
18  * @memberOf _
19  * @category Lang
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.
24  * @example
25  *
26  * var users = [
27  *   { 'user': 'barney' },
28  *   { 'user': 'fred' }
29  * ];
30  *
31  * var deep = _.cloneDeep(users);
32  * deep[0] === users[0];
33  * // => false
34  *
35  * // using a customizer callback
36  * var el = _.cloneDeep(document.body, function(value) {
37  *   if (_.isElement(value)) {
38  *     return value.cloneNode(true);
39  *   }
40  * });
41  *
42  * el === document.body
43  * // => false
44  * el.nodeName
45  * // => BODY
46  * el.childNodes.length;
47  * // => 20
48  */
49 function cloneDeep(value, customizer, thisArg) {
50   return typeof customizer == 'function'
51     ? baseClone(value, true, bindCallback(customizer, thisArg, 3))
52     : baseClone(value, true);
53 }
54
55 module.exports = cloneDeep;