Cloning copies prototype properties onto the object
See original GitHub issuefunction Test () {}
Test.prototype.val = 42;
console.log(klona(new Test())); // { val: 42 }
console.log(klona(new Test()).__proto__); // {}
Issue Analytics
- State:
- Created 4 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
JavaScript cloned object loses its prototype functions
The only way to really "clone" an object is to set its [[Prototype]] to the same object as the original, then copy the...
Read more >Prototype - Object clone() Method - Tutorialspoint
Prototype - Object clone() Method, This method clones the passed object using the shallow copy. It copies all the original's properties to the...
Read more >Cloning JavaScript Object with Object.create | by Mayank Gupta
When we create Object with Object.create, an empty Object is created and the __proto__ object is mapped to the copied Object. When __proto__...
Read more >Prototype Pattern. Creates new objects by copying an…
Swift will copy the value of the prototype and use it to create a clone. struct having reference types are shallow copied, they...
Read more >How to copy objects in JavaScript: A complete guide
A complete guide to copying objects in JavaScript: shallow copy, deep copy, assigning, merging, and structured cloning.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hey @evilebottnawi – I’m not sure what you’re switching from, but I’m guessing it’s
clone-deep
. Since you said it’s a blocker, I just wanted to let you know thatclone-deep
never actually clones a custom class instance unless you explicitly tell it to. By default, it returned the original instance. Onlylodash
– and nowklona
– return a new fresh instance of the custom class by default.You can see this here:
@lukeed can we fix it? Blocker for fully migrate on klona