Creates a deep clone of the source value.
Only arrays, JavaScript Date objects and objects that pass the isPlainObject check will be cloned. For other object types, a TypeError
will be thrown as there's no standard way to clone them. Primitive values (boolean, number, string) as well as null
and undefined
will be copied, they have value semantics anyhow.
deepClone
is designed to match the semantics of deepEqual. Any deeply cloned object should be deep-equal to the source. However, not every object that can be handled by deepEqual
can also be deeply cloned (e.g. deepClone
fails on non-plain objects).
To limit the time needed for a deep clone and to avoid endless recursion in case of cyclic structures, the recursion depth is limited by the parameter maxDepth
, which defaults to 10. When the recursion depth exceeds the given limit, a TypeError
is thrown.
Note that object identities are not honored by the clone operation. If the original source contained multiple references to the same plain object instance, the clone will contain a different clone for each reference.
Param | Type | Default Value | Description |
---|---|---|---|
src | any | Source value that shall be cloned | |
maxDepth? | int | 10 | Maximum recursion depth for the clone operation, deeper structures will throw an error |
Method | Description |
---|