function deepClone(object) {
let str
let newobj = object.constructor === Array ? [] : {}
if (typeof object !== 'object') {
return object
} else if (window.JSON) {
str = JSON.stringify(object)
newobj = JSON.parse(str)
} else {
for (const i in object) {
if (object.hasOwnProperty(i)) {
newobj[i] = typeof object[i] === 'object' ? deepClone(object[i]) : object[i]
}
}
}
return newobj
}
js深拷贝函数封装
最新推荐文章于 2022-09-02 11:43:29 发布