Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

36 рядки
1.0 KiB

4 роки тому
  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;