1

I have nested data structure which i want to clone. Some deep elements of this structure are object from foreign library with method defined as follows(this method called repeatedly in other parts of this library on this objects):

clone: function () {
            return new this.constructor( this.x, this.y, this.z );
       }

After studying Ramda docs and source more carefully i realize that the reason for my trouble was the fact that Ramda clone do not preserve constructor. I've also studied this question and understand how complicated this issue really is How do I correctly clone a JavaScript object?.

So if a can assume that my data structure wont contain any Date objects could i implement cloning through constructor (as one of the answers suggest)? What will be the best course of action? Thank you !

Anatoly Strashkevich
  • 1,834
  • 4
  • 16
  • 32
  • You can easily clone specific types; If you know how objects of that type are constructed and the data necessary to repeat that process is available in your scope (likely in the objects themselves), then you can usually replicate the process to create clones. But this won't help for arbitrary objects that might be passed to a generic `clone` function. That's why Ramda has its limitations, and it's difficult to imagine a general solution that would work quite well. – Scott Sauyet Jul 24 '17 at 00:02

0 Answers0