没用但逼格高的深拷贝

export function deepClone(obj: any) {
  return new Promise((resolve) => {
    const { port1, port2 } = new MessageChannel();
    port1.postMessage(obj);
    port2.onmessage = (msg) => {
      resolve(msg);
    };
  });
}

使用方式

let obj = {
	a:1,
	b:2
}
let newObj = deepClone(obj);

你可能感兴趣的:(前端,javascript)