mwbot-ts - v1.2.7
    Preparing search index...

    Function deepCloneInstance

    • Deeply clones a class instance, preserving its prototype, inherited properties, and special object types like Map, Set, Date, and RegExp. Also handles cyclic references.

      Features:

      • Retains the entire prototype chain, ensuring methods like toString() work as expected.
      • Recursively clones objects, including nested structures.
      • Supports special objects (Date, RegExp, Map, Set).
      • Handles cyclic references to prevent infinite loops.
      • Supports a custom _clone(seen) method if defined on the object. This allows classes to override the default cloning behavior and perform specialized cloning while still participating in cycle handling.

      Limitations:

      • WeakMap & WeakSet: Cannot be cloned because their entries are weakly held.
      • Functions & Closures: Functions are copied by reference; closures are not recreated.
      • DOM Elements & Buffers: Not supported, as they require specialized handling.

      Type Parameters

      • T extends object

      Parameters

      • obj: T

        The class instance to clone.

      • seen: WeakMap<object, any> = ...

        (Internal) A WeakMap to track visited objects for cyclic reference handling.

      Returns T

      A deep-cloned instance of the given object.