Deep cloning objects defined by JSON.

Peter van der Zee ecma at qfox.nl
Sun Jan 29 13:29:12 PST 2012


On Sun, Jan 29, 2012 at 10:09 PM, Xavier MONTILLET
<xavierm02.net at gmail.com> wrote:
> I think it should keep it. Douglas did something to allow cyclic
> references ( https://github.com/douglascrockford/JSON-js/blob/master/cycle.js
> ) and he probably wouldn't have done that if it had no use. Plus
> you're talking of cloning data structures and a graph is one.
>
> And if you do not allow cyclic references, you still have to do
> something about it. Ignoring the properties will probably make devs
> wonder why this property isn't cloned and throwing an error is, IMHO,
> no the kind of behavior you want.

Ah I'm sorry, you're right. Cyclic refs do have to be taken care of
otherwise you'll end up in an endless loop. I have no opinion on the
matter though and would suggest it to be tackled the way
JSON.stringify does it now. Whatever way that might be. Imho the
cloned object (for json.parse) should not have any refs though.

- peter


More information about the es-discuss mailing list