index.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /**
  2. * lodash 3.0.2 (Custom Build) <https://lodash.com/>
  3. * Build: `lodash modern modularize exports="npm" -o ./`
  4. * Copyright 2012-2015 The Dojo Foundation <http://dojofoundation.org/>
  5. * Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
  6. * Copyright 2009-2015 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
  7. * Available under MIT license <https://lodash.com/license>
  8. */
  9. var baseClone = require('lodash._baseclone'),
  10. bindCallback = require('lodash._bindcallback');
  11. /**
  12. * Creates a deep clone of `value`. If `customizer` is provided it's invoked
  13. * to produce the cloned values. If `customizer` returns `undefined` cloning
  14. * is handled by the method instead. The `customizer` is bound to `thisArg`
  15. * and invoked with up to three argument; (value [, index|key, object]).
  16. *
  17. * **Note:** This method is loosely based on the
  18. * [structured clone algorithm](http://www.w3.org/TR/html5/infrastructure.html#internal-structured-cloning-algorithm).
  19. * The enumerable properties of `arguments` objects and objects created by
  20. * constructors other than `Object` are cloned to plain `Object` objects. An
  21. * empty object is returned for uncloneable values such as functions, DOM nodes,
  22. * Maps, Sets, and WeakMaps.
  23. *
  24. * @static
  25. * @memberOf _
  26. * @category Lang
  27. * @param {*} value The value to deep clone.
  28. * @param {Function} [customizer] The function to customize cloning values.
  29. * @param {*} [thisArg] The `this` binding of `customizer`.
  30. * @returns {*} Returns the deep cloned value.
  31. * @example
  32. *
  33. * var users = [
  34. * { 'user': 'barney' },
  35. * { 'user': 'fred' }
  36. * ];
  37. *
  38. * var deep = _.cloneDeep(users);
  39. * deep[0] === users[0];
  40. * // => false
  41. *
  42. * // using a customizer callback
  43. * var el = _.cloneDeep(document.body, function(value) {
  44. * if (_.isElement(value)) {
  45. * return value.cloneNode(true);
  46. * }
  47. * });
  48. *
  49. * el === document.body
  50. * // => false
  51. * el.nodeName
  52. * // => BODY
  53. * el.childNodes.length;
  54. * // => 20
  55. */
  56. function cloneDeep(value, customizer, thisArg) {
  57. return typeof customizer == 'function'
  58. ? baseClone(value, true, bindCallback(customizer, thisArg, 3))
  59. : baseClone(value, true);
  60. }
  61. module.exports = cloneDeep;