TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Deep cloning objects in JavaScript, the modern way

18 pointsby steve8708over 2 years ago

1 comment

austinjpover 2 years ago
Nice but still some caveats, from [0]:<p>Prototypes. If you use structuredClone() with a class instance, you’ll get a plain object as the return value, as structured cloning discards the object’s prototype chain.<p>Functions. If your object contains functions, they will be quietly discarded.<p>Non-cloneables. Some values are not structured cloneable, most notably Error and DOM nodes. It will cause structuredClone() to throw.<p>Web workers are patchy too.<p>[0] <a href="https:&#x2F;&#x2F;web.dev&#x2F;structured-clone&#x2F;" rel="nofollow">https:&#x2F;&#x2F;web.dev&#x2F;structured-clone&#x2F;</a>