Deep cloning objects defined by JSON.

Jake Verbaten raynos2 at
Sun Jan 22 11:58:26 PST 2012

Most of the time the purpose of deep cloning objects is deep cloning data

It's been discussed that generically deep cloning proxies, privates and
functions is a non-trivial problem.

However it would be of value to have a mechanism to deep clone anything
that would be valid JSON (Limiting to JSON is arbitary, it's a well defined
subset and none of the subset would involve difficult points to resolve).

This gives us

 - An efficient deep clone implementation in the js engine
 - Solves difficulties with deep cloning by disallowing difficult objects
from being deep cloned.
 - gets rid of every clone function that every library has.

I presume this would literally be a highly optimised version of

Potential issues

 - subset of JSON is too restricted to be useful
 - Proxies/private state may cause issues (the same issues would apply to
JSON.stringify ?)
 - What's the value of the [[Prototype]] of the clone? (JSON.parse uses the
standard [[Prototype]] for the stringified object)
 - Do we expect anything sensible to happen with host objects? (JSON.parse
returns objects with few or no properties for host objects)
 - Do we solve cyclic references? (JSON.parse fails on them)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the es-discuss mailing list