Last change
on this file since 188ee53 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago |
initial commit
|
-
Property mode
set to
100644
|
File size:
1.0 KB
|
Rev | Line | |
---|
[6a3a178] | 1 | var baseClone = require('./_baseClone');
|
---|
| 2 |
|
---|
| 3 | /** Used to compose bitmasks for cloning. */
|
---|
| 4 | var CLONE_SYMBOLS_FLAG = 4;
|
---|
| 5 |
|
---|
| 6 | /**
|
---|
| 7 | * Creates a shallow clone of `value`.
|
---|
| 8 | *
|
---|
| 9 | * **Note:** This method is loosely based on the
|
---|
| 10 | * [structured clone algorithm](https://mdn.io/Structured_clone_algorithm)
|
---|
| 11 | * and supports cloning arrays, array buffers, booleans, date objects, maps,
|
---|
| 12 | * numbers, `Object` objects, regexes, sets, strings, symbols, and typed
|
---|
| 13 | * arrays. The own enumerable properties of `arguments` objects are cloned
|
---|
| 14 | * as plain objects. An empty object is returned for uncloneable values such
|
---|
| 15 | * as error objects, functions, DOM nodes, and WeakMaps.
|
---|
| 16 | *
|
---|
| 17 | * @static
|
---|
| 18 | * @memberOf _
|
---|
| 19 | * @since 0.1.0
|
---|
| 20 | * @category Lang
|
---|
| 21 | * @param {*} value The value to clone.
|
---|
| 22 | * @returns {*} Returns the cloned value.
|
---|
| 23 | * @see _.cloneDeep
|
---|
| 24 | * @example
|
---|
| 25 | *
|
---|
| 26 | * var objects = [{ 'a': 1 }, { 'b': 2 }];
|
---|
| 27 | *
|
---|
| 28 | * var shallow = _.clone(objects);
|
---|
| 29 | * console.log(shallow[0] === objects[0]);
|
---|
| 30 | * // => true
|
---|
| 31 | */
|
---|
| 32 | function clone(value) {
|
---|
| 33 | return baseClone(value, CLONE_SYMBOLS_FLAG);
|
---|
| 34 | }
|
---|
| 35 |
|
---|
| 36 | module.exports = clone;
|
---|
Note:
See
TracBrowser
for help on using the repository browser.