// 检查类型函数
export const checkType = data => Object.prototype.toString.call(data).slice(8, -1)
// 深复制数据函数
export const deepClone = target => {
let targetType = checkType(target)
let result
if (targetType === 'Object') {
result = {}
} else if (targetType === 'Array') {
result = []
} else {
return target
}
for (let i in target) {
let value = target[i]
let valueType = checkType(value)
if (valueType === 'Object' || valueType === 'Array') {
result[i] = deepClone(value)
} else {
result[i] = value
}
}
return result
}
网友评论