Deep cloning objects defined by JSON.

Rick Waldron waldron.rick at gmail.com
Sun Jan 22 14:09:10 PST 2012


On Sun, Jan 22, 2012 at 4:05 PM, Jake Verbaten <raynos2 at gmail.com> wrote:

> On Sun, Jan 22, 2012 at 8:29 PM, Rick Waldron <waldron.rick at gmail.com>wrote:
>
>> Potential issues
>>>
>>>  - subset of JSON is too restricted to be useful
>>>
>>
>> This alone seems like a deal-breaker/non-starter. How would you copy
>> methods? Forgetting about cyclic reference exceptions for a moment:
>>
>
> The idea here is that methods do not belong in data structures (clone
> should be to efficiently clone data).
>

This is already too much "unfortunate" restriction.

What about calculated "get" properties:

> var o = {
...   get foo() {
...     return "foo";
...   }
... },
... clone = JSON.parse(JSON.stringify(o));

> clone
{ foo: 'foo' }




> a possible solution would be allow you to set the [[Prototype]] of the
> returned clone through the API somehow and then store methods on prototypes.
>
> It does gain the benefit of not having to document the edge-case behaviour
> for cloning methods. It would presumably also be an API that can
> efficiently clone the new binary data types. The main purpose is efficient
> in memory copies of data and not generic cloning of things.
>
> If we add a clone, we probably want to add support for cloning binary data
> types to the list as well.
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20120122/431f5391/attachment-0001.html>


More information about the es-discuss mailing list