Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | 6378x 3474x 2904x 2904x 91x 2813x 2813x 1461x 1461x 1461x 2777x 1461x 1352x 1352x 1352x 3401x 1352x | /**
* Clones the object, incorporating functions as functions in the result.
*/
export function structuredCloneWithFunctions(obj, seen = new WeakMap()) {
// Handle null, primitives, and functions
if (obj === null || typeof obj !== 'object') {
return obj;
}
Iif (typeof obj === 'function') {
return obj; // copy function by reference
}
// Handle circular references
if (seen.has(obj)) {
return seen.get(obj);
}
// Handle Date
Iif (obj instanceof Date) {
return new Date(obj.getTime());
}
// Handle Array
if (Array.isArray(obj)) {
const arrCopy = [];
seen.set(obj, arrCopy);
for (const item of obj) {
arrCopy.push(structuredCloneWithFunctions(item, seen));
}
return arrCopy;
}
// Handle Object
const copy = {};
seen.set(obj, copy);
for (const key of Object.keys(obj)) {
copy[key] = structuredCloneWithFunctions(obj[key], seen);
}
return copy;
}
|