0

I have this object:

var a={
    objectFoo:{member1:"x",member2:"y"}
}

I want to make it have an additional identical child:

{
     objectFoo:{member1:"x",member2:"y"}
    ,objectBar:{member1:"x",member2:"y"}
}

If I do an assigment:

a.objectBar=a.objectFoo

it creates an unwanted link.

The way I handle it now is:

a.objectBar=JSON.parse(JSON.stringify(a.objectFoo))

This works, but in my novice mind feels wrong. It's like I am instructing the machine to do complex parsing stuff instead of just moving data from one point to another. Is my thinking too low level for javascript? Or is there a better way to do this?

George Menoutis
  • 5,986
  • 15
  • 35

0 Answers0