The way many browsers implement this isn't going to be particularly fast.
It serializes the objects to a byte sequence so it can be transferred to
another thread or process and then inflates the objects on the other side.
Have you benchmarked this? I think you're better off just writing your own
clone library.
On Apr 23, 2015 12:30 PM, "Martin Thomson" <martin.thomson@gmail.com> wrote:
> On 23 April 2015 at 15:02, Ted Mielczarek <ted@mozilla.com> wrote:
> > Has anyone ever proposed exposing the structured clone algorithm
> directly as an API?
>
> If you didn't just do so, I will :)
>
> > 1. https://twitter.com/TedMielczarek/status/591315580277391360
>
> Looking at your jsfiddle, here's a way to turn that into something useful.
>
> +Object.prototype.clone = Object.prototype.clone || function() {
> - function clone(x) {
> return new Promise(function (resolve, reject) {
> window.addEventListener('message', function(e) {
> resolve(e.data);
> });
> + window.postMessage(this, "*");
> - window.postMessage(x, "*");
> });
> }
>
> But are we are in the wrong place to have that discussion?
>
>