Home › Forums › JavaScript › .clone problem › Reply To: .clone problem
May 7, 2014 at 3:31 am
#169424
alisnikol
Participant
Try this,
code the clone by hand properties after properties and check that mutable instances are cloned too.
pro:
– control of what will be performed
– quick execution
cons:
– tedious to write and maintain
– bug prone (copy/paste failure, missing property, reassigned mutable property)
Use reflection:
With your own reflection tools or with an external helper (like jakarta common-beans) it is easy to write a generic copy method that will do the job in one line.
pro:
– easy to write
– no maintenance
cons:
– less control of what happens
– bug prone with mutable object if the reflection tool does not clone sub objects too
– slower execution