value to copy
copy depth (default: +infinity)
value copy
var out = copy( 'beep' );
// returns 'beep'
var value = [
{
'a': 1,
'b': true,
'c': [ 1, 2, 3 ]
}
];
var out = copy( value );
// returns [ { 'a': 1, 'b': true, 'c': [ 1, 2, 3 ] } ]
var bool = ( value[0].c === out[0].c );
// returns false
Copies or deep clones a value to an arbitrary depth.
Notes
Number
,String
, orBoolean
object is encountered, the value is cloned as a primitive. This behavior is intentional.Objects
,Arrays
, and class instances are extensible, sealed, and/or frozen.Error
instances (e.g., ES2015 subclasses).level
applies only to the class instance reference, but not to its internal state.level
must be a nonnegative integer