DEV Community

Discussion on: Deep Clone of JS Objects with circular dependency

Collapse
 
blindfish3 profile image
Ben Calder

So you could look at: github.com/lodash/lodash/blob/mast...

...and you'll discover why the usual suggestion is to not reinvent the wheel :D

TBH I'd only bother looking into a custom solution if lodash doesn't offer adequate performance and the stringify/parse approach isn't appropriate... That's not something I've had to worry about so far 🤷

Thread Thread
 
salyadav profile image
Saloni Yadav • Edited

Hi Ben,
I did take a look at the lodash implementation. And lord that's one hell of an source code! Also tried some suggestions by Dong, but looks like when things come to cyclic dependencies and a lot of corner cases, life isn't as simple!
And yes, it makes sense to only to bother about customizing the implementation when neither of the available solutions are performing as required. Thanks again! :D

P.S. It's going to take a while for me to make peace of Lodash's deep clone source code! 😂