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.
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:
toString()
work as expected.Date
,RegExp
,Map
,Set
)._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: