clone.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. /**
  2. * lodash 4.0.1 (Custom Build) <https://lodash.com/>
  3. * Build: `lodash modularize exports="es" include="clone,extend,isPlainObject,isObject,isArray,last,isEqual" --development --output src/lib/lodash`
  4. * Copyright 2012-2016 The Dojo Foundation <http://dojofoundation.org/>
  5. * Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
  6. * Copyright 2009-2016 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
  7. * Available under MIT license <https://lodash.com/license>
  8. */
  9. import baseClone from './internal/baseClone';
  10. /**
  11. * Creates a shallow clone of `value`.
  12. *
  13. * **Note:** This method is loosely based on the
  14. * [structured clone algorithm](https://mdn.io/Structured_clone_algorithm)
  15. * and supports cloning arrays, array buffers, booleans, date objects, maps,
  16. * numbers, `Object` objects, regexes, sets, strings, symbols, and typed
  17. * arrays. The own enumerable properties of `arguments` objects are cloned
  18. * as plain objects. An empty object is returned for uncloneable values such
  19. * as error objects, functions, DOM nodes, and WeakMaps.
  20. *
  21. * @static
  22. * @memberOf _
  23. * @category Lang
  24. * @param {*} value The value to clone.
  25. * @returns {*} Returns the cloned value.
  26. * @example
  27. *
  28. * var objects = [{ 'a': 1 }, { 'b': 2 }];
  29. *
  30. * var shallow = _.clone(objects);
  31. * console.log(shallow[0] === objects[0]);
  32. * // => true
  33. */
  34. function clone(value) {
  35. return baseClone(value);
  36. }
  37. export default clone;