- 深度克隆(深拷贝)
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