Coder Social home page Coder Social logo

Support for Maps and Sets about deep-copy HOT 3 OPEN

simov avatar simov commented on May 17, 2024
Support for Maps and Sets

from deep-copy.

Comments (3)

pbadenski avatar pbadenski commented on May 17, 2024 1

Makes sense. I will code up a proposal and let you know.

from deep-copy.

terrymorse58 avatar terrymorse58 commented on May 17, 2024 1

It's not just Map and Set, there are other object "types" that are being removed or mangled on the copy. These are the ones I have tested and found the results incorrect:

  • RegExp (becomes empty {})
  • Int8Array (becomes Object)
  • Uint8Array (becomes Object)
  • Uint8ClampedArray (becomes Object)
  • Int16Array (becomes Object)
  • Uint16Array (becomes Object)
  • Int32Array (becomes Object)
  • Uint32Array (becomes Object)
  • Float32Array (becomes Object)
  • Float64Array (becomes Object)
  • BigInt64Array (becomes Object)
  • BigUint64Array (becomes Object)

Example from my RegExp test:

let src = [1, 2, /abc/, "foo"];
let dest = deepCopy(src);
dest10[3] = "BAR";
console.log(src); // [ 1, 2, /abc/, 'foo' ]
console.log(dest); // [ 1, 2, {}, 'BAR' ]

Also, it's not preserving non-enumerable properties on the copy. I suggest this could be a configurable option—that seems to be the common way to handle those in other modules.

I started a new module named deep-copy-all that handles these new object types. It includes a test suite to validate the handling of the new objects.

from deep-copy.

simov avatar simov commented on May 17, 2024

I'm not sure how similar cloning implementation for Map and Set would look like. Probably a separate module would be better, though I would be interested to see how it look like when ready.

from deep-copy.

Related Issues (1)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.