Skip to content

Instantly share code, notes, and snippets.

@fodra
Created January 26, 2018 11:55
Show Gist options
  • Save fodra/64ed84564d6f2a8d9d226711fd43c85d to your computer and use it in GitHub Desktop.
Save fodra/64ed84564d6f2a8d9d226711fd43c85d to your computer and use it in GitHub Desktop.
This is how you perform a deep copy in javascript as discussed in the HN article: Deep-copying in JavaScript.
function deepCopy(obj) {
return new Promise(resolve => {
const {send, recv} = new MessageChannel();
recv.onmessage = ev => resolve(ev.data);
send.postMessage(obj);
});
}
const obj = /* object to copy */;
const clone = await deepCopy(obj);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment