// source是什么类型
// target就传入相同类型
const obj = {
name: 'jack',
age: 18,
hobbies: ['唱', '跳', 'rap']
}
const arr = [2, [23]]
function deepCopy(source, target) {
for (let k in source) {
let item = source[k]
if (item instanceof Array) {
target[k] = []
deepCopy(item, target[k])
} else if (item instanceof Object) {
target[k] = {}
deepCopy(item, target[k])
} else {
target[k] = item
}
}
}
let o = {}
let a = []
// deepCopy(obj, o)
deepCopy(arr, a)
console.log(a)