function shadowCopy(obj) {
if (typeof obj !== 'function' && typeof obj !== 'object') {
return obj;
}
let fake = Array.isArray(obj) ? [] : {};
for (let i in obj) {
fake[i] = obj[i];
}
return fake;
}
const originalData = { a: 1, b: { c: 2}};
const fakeShadowData = shadowCopy(originalData);
function isObject(obj) {
return typeof obj === 'function' || typeof obj === 'object';
}
function deepClone(obj, map = new Map()) {
if (typeof obj === 'object') {
let clone = Array.isArray(obj) ? [] : {};
if(map.get(obj)) {
return map.get(obj);
}
for(let i in obj) {
clone[i] = deepClone(clone[i], map);
}
return clone;
} else {
return obj;
}
}
let fakeDeepData = deepClone(originalData);
fakeDeepData.a = 2;
fakeDeepData.b.c = 4;
console.log('fakeDeepData', fakeDeepData);
console.log('originalData', originalData);
console