fix/build-nobelium

This commit is contained in:
tangly1024.com
2023-08-01 14:17:30 +08:00
parent 72dbf54e11
commit 570ab5a13c

View File

@@ -112,24 +112,32 @@ export function isIterable(obj) {
return obj != null && typeof obj[Symbol.iterator] === 'function'
}
/**
* 深拷贝对象
* 根据源对象类型深度复制支持object和array
* @param {*} obj
* @returns
*/
export function deepClone(obj) {
const newObj = Array.isArray(obj) ? [] : {}
if (obj && typeof obj === 'object') {
if (Array.isArray(obj)) {
// If obj is an array, create a new array and deep clone each element
return obj.map(item => deepClone(item))
} else if (obj && typeof obj === 'object') {
const newObj = {}
for (const key in obj) {
if (Object.prototype.hasOwnProperty.call(obj, key)) {
if (obj[key] instanceof Date) { // 判断属性值是否为 Date 对象
newObj[key] = new Date(obj[key].getTime()).toISOString() // 直接拷贝引用
} else if (obj[key] && typeof obj[key] === 'object') {
newObj[key] = deepClone(obj[key])
if (obj[key] instanceof Date) {
newObj[key] = new Date(obj[key].getTime()).toISOString()
} else {
newObj[key] = obj[key]
newObj[key] = deepClone(obj[key])
}
}
}
return newObj
} else {
return obj
}
return newObj
}
/**
* 延时
* @param {*} ms