JS 对象深拷贝

117 阅读1分钟


function deepCopy(target){
  const copy = {};
  for(let key in target){
    if(typeof target[key] === 'object'){
      copy[key] = deepCopy(target[key])
    } else {
      copy[key] = target[key];
    }
  }
  
  return copy;
}

本文使用 mdnice 排版