refactoring deepClone

This commit is contained in:
Serge Gao 2018-01-22 10:34:21 +08:00 committed by GitHub
parent 700e08b795
commit 3bed61fd07
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 1 additions and 14 deletions

View File

@ -249,19 +249,6 @@ export function debounce(func, wait, immediate) {
} }
export function deepClone(source) { export function deepClone(source) {
if (!source && typeof source !== 'object') { let targetObj = JSON.parse(JSON.stringify(source));
throw new Error('error arguments', 'shallowClone')
}
const targetObj = source.constructor === Array ? [] : {}
for (const keys in source) {
if (source.hasOwnProperty(keys)) {
if (source[keys] && typeof source[keys] === 'object') {
targetObj[keys] = source[keys].constructor === Array ? [] : {}
targetObj[keys] = deepClone(source[keys])
} else {
targetObj[keys] = source[keys]
}
}
}
return targetObj return targetObj
} }