Stop object referencing 3

I have a temp object and a temp object if I do this tempObj = obj

and change stuff in tempObj, these changes affect obj, is there any way I can stop this from doing this? Regards Mark

+1


a source to share


2 answers


This is the standard behavior in many languages. When you do tempObj = obj you are NOT creating a duplicate object. You are creating another link to the same object.

I don't think you can change this behavior, and of course I don't think you should :)



You need to create another object, a duplicate of the original object. You can implement a function for this. Maybe this can help http://blog.comtaste.com/2007/10/improving_object_copy.html

Good luck!

+2


a source


What you are doing is linking to the original object, not a copy of the original. You must create a deep copy of your object. It seems like someone already wrote the steps to do this ...

http://www.as3dp.com/2008/09/23/actionscript-30-clone-a-prelude-to-the-prototype-design-pattern/



Hope it helps

+1


a source







All Articles