clone.js 984 B

123456789101112131415161718192021222324252627282930313233
  1. var baseClone = require('./_baseClone');
  2. /**
  3. * Creates a shallow clone of `value`.
  4. *
  5. * **Note:** This method is loosely based on the
  6. * [structured clone algorithm](https://mdn.io/Structured_clone_algorithm)
  7. * and supports cloning arrays, array buffers, booleans, date objects, maps,
  8. * numbers, `Object` objects, regexes, sets, strings, symbols, and typed
  9. * arrays. The own enumerable properties of `arguments` objects are cloned
  10. * as plain objects. An empty object is returned for uncloneable values such
  11. * as error objects, functions, DOM nodes, and WeakMaps.
  12. *
  13. * @static
  14. * @memberOf _
  15. * @since 0.1.0
  16. * @category Lang
  17. * @param {*} value The value to clone.
  18. * @returns {*} Returns the cloned value.
  19. * @see _.cloneDeep
  20. * @example
  21. *
  22. * var objects = [{ 'a': 1 }, { 'b': 2 }];
  23. *
  24. * var shallow = _.clone(objects);
  25. * console.log(shallow[0] === objects[0]);
  26. * // => true
  27. */
  28. function clone(value) {
  29. return baseClone(value, false, true);
  30. }
  31. module.exports = clone;