dandanyajin
今天更新博客了吗?
export const deepClone = (source)=>{
  if (!source && typeof source !== 'object') {
    throw new Error('error arguments', 'deepClone')
  }
  const targetObj = source.constructor === Array ? [] : {}
  Object.keys(source).forEach(keys => {
    if (source[keys] && typeof source[keys] === 'object') {
      targetObj[keys] = deepClone(source[keys])
    } else {
      targetObj[keys] = source[keys]
    }
  })
  return targetObj
}

 

posted on 2022-07-28 14:05  dandanyajin  阅读(8)  评论(0编辑  收藏  举报