Deep cloning JS objects has a plethora of blog posts and articles over the internet. But as I see, most or rather all of them end up with a solution of stringifying the JSON object and parsing them back. Somehow I am really unsettled with this solution. Is there any other way of deep clone a JS object?
Let's take some scenarios to discuss:
1- Not just one level of nested object, how about atleast 10?
2- What if after a certain point, there is circular dependency in the objects. (Ever heard of the tortoise-hare algorithm in linked list?) How will be approach cloning such an object?
P.S. I do not want to
Why I don't what to use JSON.stringify?
I came across this article on Medium.
And it was pretty convincing of certain loopholes in using
I agree that this is the most effective way to convert an object, but I am in a quest for a non-work-around solution. We will deal with performance of cloning later. For now, a base solution!