From 3f479664b6ed1b89af46556df703a9e981e5988e Mon Sep 17 00:00:00 2001 From: Pan Date: Tue, 19 Jun 2018 11:26:46 +0800 Subject: [PATCH] perf[utils.js]: Add code comments to deepClone and remove redundant code --- src/utils/index.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/utils/index.js b/src/utils/index.js index 431fda2d..31295122 100644 --- a/src/utils/index.js +++ b/src/utils/index.js @@ -246,6 +246,11 @@ export function debounce(func, wait, immediate) { } } +/** + * This is just a simple version of deep copy + * Has a lot of edge cases bug + * If you want to use a perfect deep copy, use lodash's _.cloneDeep + */ export function deepClone(source) { if (!source && typeof source !== 'object') { throw new Error('error arguments', 'shallowClone') @@ -253,7 +258,6 @@ export function deepClone(source) { const targetObj = source.constructor === Array ? [] : {} Object.keys(source).forEach((keys) => { if (source[keys] && typeof source[keys] === 'object') { - targetObj[keys] = source[keys].constructor === Array ? [] : {} targetObj[keys] = deepClone(source[keys]) } else { targetObj[keys] = source[keys]