首页 > 其他分享 >深度克隆(深拷贝)

深度克隆(深拷贝)

时间:2022-12-30 00:00:29浏览次数:40  
标签:const 克隆 deepClone targetObj 深度 拷贝 data

  • 深度克隆(深拷贝)
export const deepClone = (targetObj)=> {
  return new Promise(resolve => {
    const { port1, port2 } = new MessageChannel();
    port1.postMessage(targetObj);
    port2.onmessage = (msg)=> {
      resolve(msg.data)
    }
  })
}
import { deepClone } from "./tool.js"
let obj = {
   name: "码农权",
   aihao: ["画画", "跳舞"]
}
const copyObj = async (targetObj)=> {
  const data = await deepClone(targetObj)
  console.log(data)
}
copyObj(obj)

标签:const,克隆,deepClone,targetObj,深度,拷贝,data
From: https://www.cnblogs.com/bingquan1/p/17013844.html

相关文章