cloneDeepWith.js 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. var baseClone = require('./_baseClone');
  2. /** Used to compose bitmasks for cloning. */
  3. var CLONE_DEEP_FLAG = 1,
  4. CLONE_SYMBOLS_FLAG = 4;
  5. /**
  6. * This method is like `_.cloneWith` except that it recursively clones `value`.
  7. *
  8. * @static
  9. * @memberOf _
  10. * @since 4.0.0
  11. * @category Lang
  12. * @param {*} value The value to recursively clone.
  13. * @param {Function} [customizer] The function to customize cloning.
  14. * @returns {*} Returns the deep cloned value.
  15. * @see _.cloneWith
  16. * @example
  17. *
  18. * function customizer(value) {
  19. * if (_.isElement(value)) {
  20. * return value.cloneNode(true);
  21. * }
  22. * }
  23. *
  24. * var el = _.cloneDeepWith(document.body, customizer);
  25. *
  26. * console.log(el === document.body);
  27. * // => false
  28. * console.log(el.nodeName);
  29. * // => 'BODY'
  30. * console.log(el.childNodes.length);
  31. * // => 20
  32. */
  33. function cloneDeepWith(value, customizer) {
  34. customizer = typeof customizer == 'function' ? customizer : undefined;
  35. return baseClone(value, CLONE_DEEP_FLAG | CLONE_SYMBOLS_FLAG, customizer);
  36. }
  37. module.exports = cloneDeepWith;