Skip to content

Commit 3f47966

Browse files
committed
perf[utils.js]: Add code comments to deepClone and remove redundant code
1 parent cbee7b6 commit 3f47966

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/utils/index.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,14 +246,18 @@ export function debounce(func, wait, immediate) {
246246
}
247247
}
248248

249+
/**
250+
* This is just a simple version of deep copy
251+
* Has a lot of edge cases bug
252+
* If you want to use a perfect deep copy, use lodash's _.cloneDeep
253+
*/
249254
export function deepClone(source) {
250255
if (!source && typeof source !== 'object') {
251256
throw new Error('error arguments', 'shallowClone')
252257
}
253258
const targetObj = source.constructor === Array ? [] : {}
254259
Object.keys(source).forEach((keys) => {
255260
if (source[keys] && typeof source[keys] === 'object') {
256-
targetObj[keys] = source[keys].constructor === Array ? [] : {}
257261
targetObj[keys] = deepClone(source[keys])
258262
} else {
259263
targetObj[keys] = source[keys]

0 commit comments

Comments
 (0)