Last active
January 24, 2018 17:17
-
-
Save oliverturner/3a3f3f8f3856279779b297a8ff2c6791 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
async function structuredClone(obj) { | |
return new Promise(resolve => { | |
const { port1, port2 } = new MessageChannel(); | |
port2.onmessage = evt => resolve(evt.data); | |
port1.postMessage(obj); | |
}); | |
} | |
// Usage | |
const a = { a: 1, b: 2, c: [1, 2, 3], d: { person: { name: "oliver" } } }; | |
const { d } = await structuredClone(a); | |
console.log(d); // <= {person: {name:"oliver"}} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment