/**
* 对象深度克隆
* @param obj
* @author liudongcai
* @returns
*/
export function deepclone(obj: any): any {
function copyList(arr: Array<any>): any {
const result = []
for (let item of arr) {
result.push(deepclone(item))
}
return result
}
if (typeof obj === "object") {
if (Array.isArray(obj)) {
return copyList(obj)
} else {
const result: { [key: string]: any } = {}
for (let key in obj) {
result[key] = deepclone(obj[key])
}
result.__proto__ = Object.getPrototypeOf(obj)
return result
}
} else {
return obj
}
}
ts class的深度克隆包含函数
于 2023-06-30 16:43:22 首次发布