react / wstein / node_modules / jest-cli / node_modules / istanbul / node_modules / js-yaml / node_modules / argparse / node_modules / lodash / lang / clone.js
80742 viewsvar baseClone = require('../internal/baseClone'),1bindCallback = require('../internal/bindCallback'),2isIterateeCall = require('../internal/isIterateeCall');34/**5* Creates a clone of `value`. If `isDeep` is `true` nested objects are cloned,6* otherwise they are assigned by reference. If `customizer` is provided it is7* invoked to produce the cloned values. If `customizer` returns `undefined`8* cloning is handled by the method instead. The `customizer` is bound to9* `thisArg` and invoked with two argument; (value [, index|key, object]).10*11* **Note:** This method is loosely based on the12* [structured clone algorithm](http://www.w3.org/TR/html5/infrastructure.html#internal-structured-cloning-algorithm).13* The enumerable properties of `arguments` objects and objects created by14* constructors other than `Object` are cloned to plain `Object` objects. An15* empty object is returned for uncloneable values such as functions, DOM nodes,16* Maps, Sets, and WeakMaps.17*18* @static19* @memberOf _20* @category Lang21* @param {*} value The value to clone.22* @param {boolean} [isDeep] Specify a deep clone.23* @param {Function} [customizer] The function to customize cloning values.24* @param {*} [thisArg] The `this` binding of `customizer`.25* @returns {*} Returns the cloned value.26* @example27*28* var users = [29* { 'user': 'barney' },30* { 'user': 'fred' }31* ];32*33* var shallow = _.clone(users);34* shallow[0] === users[0];35* // => true36*37* var deep = _.clone(users, true);38* deep[0] === users[0];39* // => false40*41* // using a customizer callback42* var el = _.clone(document.body, function(value) {43* if (_.isElement(value)) {44* return value.cloneNode(false);45* }46* });47*48* el === document.body49* // => false50* el.nodeName51* // => BODY52* el.childNodes.length;53* // => 054*/55function clone(value, isDeep, customizer, thisArg) {56if (isDeep && typeof isDeep != 'boolean' && isIterateeCall(value, isDeep, customizer)) {57isDeep = false;58}59else if (typeof isDeep == 'function') {60thisArg = customizer;61customizer = isDeep;62isDeep = false;63}64return typeof customizer == 'function'65? baseClone(value, isDeep, bindCallback(customizer, thisArg, 1))66: baseClone(value, isDeep);67}6869module.exports = clone;707172