function deepClone(obj,hash = new Map()){
if(obj===null||typeof obj!=='object'){
return obj
}
if(hash.has(obj)){
return hash.get(obj)
}
const clone = Array.isArray(obj)?[]:{}
hash.set(obj,clone)
for(let key in obj){
if(Object.prototype.hasOwnProperty.call(obj,key)){
clone[key] = deepClone(obj[key],hash)
}
}
return clone;
}
const originalObj = {
name: 'John',
age: 30,
address: {
street: '123 Main St',
city: 'New York'
}
};
const clonedObj = deepClone(originalObj);
console.log(clonedObj); // 输出深拷贝后的对象
console.log(originalObj === clonedObj); // 输出 false,说明是不同的对象
console