Deep cloning objects defined by JSON.

Rick Waldron waldron.rick at gmail.com
Mon Jan 23 16:16:32 PST 2012



On Jan 23, 2012, at 4:58 PM, Russell Leggett <russell.leggett at gmail.com> wrote:

> On Mon, Jan 23, 2012 at 5:37 AM, Herby Vojčík <herby at mailbox.sk> wrote:
> Allen Wirfs-Brock wrote:
> The following is just speculation...One possible such bottleneck
> might be whole object allocation. A JS clone function probably would
> have to allocate an empty object and then dynamically populate it by
> adding properties one at a time.  A native implementation is more
> like to have the ability to examine a complete object and create, in
> a single primitive operation, a new object with all of the same
> properties as the original object.  In other words, a native
> implementation of deep clone is likely to use some sort of shallow
> clone operation is that not available to pure JS code.  This suggest
> that a better way to get faster deep cloning functions is to make a
> native shallow clone function available to JS code.
> 
> +1, nice.
> Well, to see if this is the bottleneck, one needs to benchmark, first.
> 
> But I feel the need for shallow clone in the language. Such API should be there, and if needed, with native implementation as well.
> 
>  
> As part of the HTML5 specification, there is the structured clone algorithm  

Which is also incapable of copying a function.


> whose primary use case is web workers. It has already been implemented in Chrome and Firefox, I believe. Not sure if that might be a good place to start in possibly exposing that as part of JavaScript.
> 
> If I were to make a feature request here, instead of a clone that might not be terribly useful, I would love to see some better support for Clojure style persistent data structures.
> 
> I know that's a bit of a long shot, but for all the uses of deep cloning I can think of, I feel like persistent data structures are much nicer, and harder to implement in JS.
> 
> - Russ
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20120123/946e938d/attachment.html>


More information about the es-discuss mailing list