Joined March 2012
·

Marcio Gasparotto

Sr. at Synchro
·
Campinas
·
·
·

Posted to Cloning Javascript Objects over 1 year ago

Hi!

This works great for a pojo:

var originalObject = {
    items:[
        {id:1, text:"Item 1" },
        {id:2, text:"Item 2" }
    ],
    other:{
        foo:{
            bar:'bar', 
            foo:'foo',
            ary: [ 
                [
                    {id:1, text:"Item 1" }, {id:2, text:"Item 2" }
                ],
                [
                    {id:1, text:"Item 1" }, {id:2, text:"Item 2" }
                ]
            ]
        } 
    }
}

var clonedObject = JSON.parse(JSON.stringify(originalObject));

In your case, a replacer maybe help you. Good luck!

Hi David!

I'm use this wrapper in my initializer folder:
https://gist.github.com/marcio/5808694#file-will_paginate-rb

Achievements
117 Karma
6,429 Total ProTip Views