12/03/2009
Copy by value for JSON objects
Posted by
Henry Ji
In Javascript, if you assign a reference object to another object, you actually copy it by reference. Therefore, when I wanted to create a new JSON object to have the same structure as an existing object, I tried to find a deep copy function in JavaScript first. And then I found out another way to tackle it - I stringify the existing JSON object and eval the resultant string to the new JSON object. It works just like copy by value.
Here you can find an JSON stringify function.
« Back to Blog Main Page |