Não pode escolher mais do que 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

36 linhas
1.0 KiB

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