SO answer / how to duplicate object attributes in another object

http://stackoverflow.com/questions/9362716/how-to-duplicate-object-attributes-in-another-object

by KooiInc MeHere

JavaScript

var foo = {
            a: {aa:1,bb:2},
            b: [3,4],
            c: 'sometest',
            d: 'hello world'
          },
    bar = { foo: JSON.parse(JSON.stringify(foo)),
            x: 'done'
          };


console.log(bar.foo.b[1]); //=> 4

//if foo contains methods, why not assign by reference?
var foo = {
            a: {aa:1,bb:2},
            b: [3,4],
            c: 'sometest',
            d: 'hello world',
            e: function(){alert('hi');}
          },
    bar = { foo: foo,
            x: 'done'
           };

bar.foo.e();
console.log(bar.foo.c); //=> sometest