From 3bed61fd073d9e4374db2ae79044dbb8cd90b052 Mon Sep 17 00:00:00 2001 From: Serge Gao Date: Mon, 22 Jan 2018 10:34:21 +0800 Subject: [PATCH] refactoring deepClone --- src/utils/index.js | 15 +-------------- 1 file changed, 1 insertion(+), 14 deletions(-) diff --git a/src/utils/index.js b/src/utils/index.js index 2140fdff..4b7388e2 100644 --- a/src/utils/index.js +++ b/src/utils/index.js @@ -249,19 +249,6 @@ export function debounce(func, wait, immediate) { } export function deepClone(source) { - if (!source && typeof source !== 'object') { - 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] - } - } - } + let targetObj = JSON.parse(JSON.stringify(source)); return targetObj }