Loading problem…
This problem builds on deep-clone-ii. Complete that first, then load your solution to continue.
Implement a configurable deepClone that extends level-II cloning with symbol keys, function policy, weak-collection policy, and custom handlers.
deepClone(value, options?)cloneFunctions (boolean, default false)false: keep original function reference.true: return a callable wrapper function.customHandlers (object, default {})Date, URL).(value, clone) => any.weakCollections ("empty" | "reference", default "empty")"empty": clone WeakMap/WeakSet as new empty instances."reference": reuse original WeakMap/WeakSet references.cloneFunctions.weakCollections.const sym = Symbol("k")
const original = { [sym]: { n: 1 } }
const cloned = deepClone(original)
cloned[sym].n = 9
// original[sym].n is still 1const out = deepClone({ when: new Date("2023-01-01") }, {
customHandlers: {
Date: (d) => `DATE:${d.toISOString()}`
}
})
// out.when is "DATE:2023-01-01T00:00:00.000Z"