Last active
January 24, 2019 22:34
-
-
Save Vanilagy/d73e3f466d50d238b769cd9b391dd273 to your computer and use it in GitHub Desktop.
HTML Structured Clone Algorithm directly exposed in JavaScript using BroadcastChannels
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
// @Vanilagy 2019 | |
// | |
// Example: | |
// structuredClone([5, {hello: 'world'}, new Set()]).then((data) => console.log(data)); | |
// > [5, {hello: "world"}, Set(0)] | |
var structuredClone = (function() { | |
var sender = new BroadcastChannel('structuredClone'), | |
receiver = new BroadcastChannel('structuredClone'); | |
return function(data) { | |
return new Promise((resolve) => { | |
receiver.onmessage = (e) => resolve(e.data); | |
sender.postMessage(data); | |
}); | |
}; | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment