题解 | #简易深拷贝#

简易深拷贝

https://www.nowcoder.com/practice/3d436d07f5cb4b628a4dd7c12476cabe

 const _sampleDeepClone = target => {
   if (typeof target != 'object' || !target) return target

  let constructor = target.constructor
  let result = new constructor()

  for (let key in target) {
  	if (target.hasOwnProperty(key)) {
		result[key] = _sampleDeepClone(target[key])
	}
  }

  return result
}

全部评论

相关推荐

uu们,拒offer时hr很生气怎么办我哭死
爱睡觉的冰箱哥:人家回收你的offer,或者oc后没给你发offer的时候可不会愧疚你,所以你拒了也没必要愧疚他。
点赞 评论 收藏
分享
每晚夜里独自颤抖:你cet6就cet6,cet4就cet4,你写个cet证书等是什么意思。专业技能快赶上项目行数,你做的这2个项目哪里能提现你有这么多技能呢
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务