// 深拷贝
function deepClone(obj) {
if (!obj || typeof obj !== 'object') {
return obj
}
let result
// if (Array.isArray(obj)) {
// result = []
// } else {
// result = {}
// }
if (obj instanceof Array) {
result = []
} else {
result = {}
}
for (let key in obj) {
if (obj.hasOwnProperty(key)) {
result[key] = deepClone(obj[key])
}
}
return result
}
js深拷贝
最新推荐文章于 2025-07-15 08:30:36 发布