Options
All
  • Public
  • Public/Protected
  • All
Menu

External module "utils/copy/docs/types/index.d"

Index

Functions

Functions

copy

  • copy(value: any, level?: undefined | number): any
  • Copies or deep clones a value to an arbitrary depth.

    Notes

    • The implementation can handle circular references.
    • If a Number, String, or Boolean object is encountered, the value is cloned as a primitive. This behavior is intentional.
    • For objects, the implementation only copies enumerable keys and their associated property descriptors.
    • The implementation only checks whether basic Objects, Arrays, and class instances are extensible, sealed, and/or frozen.
    • Functions are not cloned; their reference is copied.
    • The implementation supports custom error types which are Error instances (e.g., ES2015 subclasses).
    • Support for copying class instances is inherently fragile. Any instances with privileged access to variables (e.g., within closures) cannot be cloned. This stated, basic copying of class instances is supported. Provided an environment which supports ES5, the implementation is greedy and performs a deep clone of any arbitrary class instance and its properties. The implementation assumes that the concept of level applies only to the class instance reference, but not to its internal state.
    throws

    level must be a nonnegative integer

    Parameters

    • value: any

      value to copy

    • Optional level: undefined | number

      copy depth (default: +infinity)

    Returns any

    value copy

    Example

    var out = copy( 'beep' );
    // returns 'beep'

    Example

    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