Ohm-Management - Projektarbeit B-ME
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

cloneWith.js 1.2KB

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