COBOL-guy questions : Why is simple complex?

COBOL-guy questions : Why is simple complex?

var

test = {} ;

test.simple = {} ;

test.simple.par1 = 1;

test.complex = test.simple;

test.complex.par2 = 2;

alert( JSON.stringify(

test. simple));

And how to prevent?

]]>

4 Commentsto COBOL-guy questions : Why is simple complex?

  1. Anonymous says:

    < ![CDATA[

    Simple is complex, because complex and simple contani the same reference. You have to copy the whole object. I don’t know how to do that best.

    ]]>

  2. Anonymous says:

    < ![CDATA[

    https://www.google.com/search?q=javascript+clone+object



    Yes, it’s a Google search link.


    It seems that it depends on the complexity of the object you want to clone, and how fast you want it to be done.



    For simple objects use


    test.complex=JSON.parse(JSON.stringify(test.simple));

    ]]>

  3. Anonymous says:

    < ![CDATA[

    hhhm, especially when in my original script test is ‘attached’ to self…..

    ]]>

  4. Anonymous says:

    < ![CDATA[

    TrianguloY​ never would have Googled with clone, maybe expand. But thanks for your reply. Even complex is not too big to copy the code completely.

    ]]>

Leave a Reply

Your email address will not be published. Required fields are marked *