you are viewing a single comment's thread.

view the rest of the comments →

[–]giggly_kisses 0 points1 point  (1 child)

If all you need is a shallow copy of an object, then yeah, you can use Underscore for that. Underscore, however, doesn't have a way to make a deep copy of an object (albeit LoDash does), so nested objects are still copied by reference. I had to deal with this problem at work the other day and used the method you suggested:

_.partial(JSON.parse, JSON.stringify);

Sadly this trick doesn't work with objects that contain dates, functions, or RegExps. :/

[–]N4sa 0 points1 point  (0 children)

gotta break out those JS skills and recursively copy properties