Deep cloning objects defined by JSON.

Herby Vojčík herby at mailbox.sk
Mon Jan 23 02:37:23 PST 2012


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.

> Allen

Herby


More information about the es-discuss mailing list