cloneWith.js 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. var baseClone = require('./_baseClone');
  2. /**
  3. * This method is like `_.clone` except that it accepts `customizer` which
  4. * is invoked to produce the cloned value. If `customizer` returns `undefined`,
  5. * cloning is handled by the method instead. The `customizer` is invoked with
  6. * up to four arguments; (value [, index|key, object, stack]).
  7. *
  8. * @static
  9. * @memberOf _
  10. * @since 4.0.0
  11. * @category Lang
  12. * @param {*} value The value to clone.
  13. * @param {Function} [customizer] The function to customize cloning.
  14. * @returns {*} Returns the cloned value.
  15. * @see _.cloneDeepWith
  16. * @example
  17. *
  18. * function customizer(value) {
  19. * if (_.isElement(value)) {
  20. * return value.cloneNode(false);
  21. * }
  22. * }
  23. *
  24. * var el = _.cloneWith(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. * // => 0
  32. */
  33. function cloneWith(value, customizer) {
  34. return baseClone(value, false, true, customizer);
  35. }
  36. module.exports = cloneWith;