1 var baseClone = require('../internal/baseClone'),
2 bindCallback = require('../internal/bindCallback'),
3 isIterateeCall = require('../internal/isIterateeCall');
6 * Creates a clone of `value`. If `isDeep` is `true` nested objects are cloned,
7 * otherwise they are assigned by reference. If `customizer` is provided it's
8 * invoked to produce the cloned values. If `customizer` returns `undefined`
9 * cloning is handled by the method instead. The `customizer` is bound to
10 * `thisArg` and invoked with up to three argument; (value [, index|key, object]).
12 * **Note:** This method is loosely based on the
13 * [structured clone algorithm](http://www.w3.org/TR/html5/infrastructure.html#internal-structured-cloning-algorithm).
14 * The enumerable properties of `arguments` objects and objects created by
15 * constructors other than `Object` are cloned to plain `Object` objects. An
16 * empty object is returned for uncloneable values such as functions, DOM nodes,
17 * Maps, Sets, and WeakMaps.
22 * @param {*} value The value to clone.
23 * @param {boolean} [isDeep] Specify a deep clone.
24 * @param {Function} [customizer] The function to customize cloning values.
25 * @param {*} [thisArg] The `this` binding of `customizer`.
26 * @returns {*} Returns the cloned value.
30 * { 'user': 'barney' },
34 * var shallow = _.clone(users);
35 * shallow[0] === users[0];
38 * var deep = _.clone(users, true);
39 * deep[0] === users[0];
42 * // using a customizer callback
43 * var el = _.clone(document.body, function(value) {
44 * if (_.isElement(value)) {
45 * return value.cloneNode(false);
49 * el === document.body
53 * el.childNodes.length;
56 function clone(value, isDeep, customizer, thisArg) {
57 if (isDeep && typeof isDeep != 'boolean' && isIterateeCall(value, isDeep, customizer)) {
60 else if (typeof isDeep == 'function') {
65 return typeof customizer == 'function'
66 ? baseClone(value, isDeep, bindCallback(customizer, thisArg, 3))
67 : baseClone(value, isDeep);
70 module.exports = clone;