Zum Hauptinhalt springen
tsecurity.de LIVE
Echtzeit-Radar & Feeds
Alle RSS Feeds
👥 Community & Social
Sichere ProgrammierungBreeze TTS 2 vs ElevenLabs: Open Source TTS Verdict(23.09.2026 um 05:44 Uhr)
Sichere ProgrammierungAgentic AI vs Generative AI: The 2026 Verdict(23.09.2026 um 05:44 Uhr)
Sichere ProgrammierungI made my agent prove every quote against the source document(23.09.2026 um 05:45 Uhr)
Sichere Programmierung8mb.video Alternative: Skip the Line, Skip the Upsell(23.09.2026 um 05:47 Uhr)
Sichere ProgrammierungBuilding a GTA 6 JSON API for entities and current status(23.09.2026 um 05:52 Uhr)
Sichere ProgrammierungEvery filter needs a documented exception(23.09.2026 um 06:01 Uhr)
Sichere ProgrammierungBreeze TTS 2 vs ElevenLabs: Open Source TTS Verdict(23.09.2026 um 05:44 Uhr)
Sichere ProgrammierungAgentic AI vs Generative AI: The 2026 Verdict(23.09.2026 um 05:44 Uhr)
Sichere ProgrammierungI made my agent prove every quote against the source document(23.09.2026 um 05:45 Uhr)
Sichere Programmierung8mb.video Alternative: Skip the Line, Skip the Upsell(23.09.2026 um 05:47 Uhr)
Sichere ProgrammierungBuilding a GTA 6 JSON API for entities and current status(23.09.2026 um 05:52 Uhr)
Sichere ProgrammierungEvery filter needs a documented exception(23.09.2026 um 06:01 Uhr)
Intelligence View
⚡ tsecurity.de Intelligence

structuredClone() — The Deep Copy Hero JavaScript Deserved 🦸‍♀️

Let’s be honest. Every JavaScript developer has broken production at least once because of copying objects the wrong way. You thought you cloned it. JavaScript smiled. Then changed the original too. Enter structuredClone() — the native de…

0
↗ Quelle (dev.to)
Reagiere als Erste:r — dein Feedback zählt!

Let’s be honest.


Every JavaScript developer has broken production at least once because of copying objects the wrong way.



You thought you cloned it.


JavaScript smiled.


Then changed the original too.



Enter structuredClone() — the native deep-cloning superhero that finally says:




“Relax. I got this.”








The Problem: “Why did my original object change?! 😭”



Classic situation:




const user = {
name: "Shanthi",
skills: ["JavaScript", "React"]
};

const copy = user;
copy.skills.push("TypeScript");

console.log(user.skills);
// ["JavaScript", "React", "TypeScript"] 😱






You didn’t mean to update the original…


JavaScript just assumed you were feeling adventurous.







The Old (Painful) Way 😬



We all tried this at some point:




JSON.parse(JSON.stringify(obj))






It looks clever.


It feels clever.


But it betrays you silently.







What it breaks:




  • Date becomes a string

  • Map, Set vanish into thin air

  • undefined, NaN, Infinity disappear

  • ❌ Circular references? App crash 💥



Basically, it copies your data and forgets its personality.







Meet structuredClone() 🧠✨



JavaScript finally said:




“Okay fine, here’s a proper deep clone.”







const cloned = structuredClone(original);






That’s it.


No imports.


No libraries.


No emotional damage.









What Makes structuredClone So Cool?



✅ It actually understands JavaScript data.






It supports:




  • Objects & Arrays


  • Date


  • Map, Set


  • RegExp


  • BigInt

  • TypedArrays

  • Circular references (YES 🔥)



Basically, real-world data. Not just JSON-shaped dreams.









Example: Deep Clone That Actually Works






const user = {
name: "Shanthi",
meta: {
joined: new Date(),
},
};

const clone = structuredClone(user);

clone.meta.joined.setFullYear(2030);

console.log(user.meta.joined.getFullYear());
// Still 2024 😌






No side effects.


No surprises.


No apology messages to your team.









Circular References? Bring It On 💪






const obj = {};
obj.self = obj;

const cloned = structuredClone(obj);

console.log(cloned.self === cloned); // true






Old methods would:




  • ❌ Cry

  • ❌ Throw errors

  • ❌ Give up on life



structuredClone just nods politely and continues.









Map & Set — Finally Respected 🫶






const data = {
map: new Map([["a", 1]]),
set: new Set([1, 2, 3]),
};

const clone = structuredClone(data);

clone.map.set("b", 2);

console.log(data.map.has("b")); // false 🎉






Your original data remains unbothered.









What It Won’t Clone (And That’s Fair)



Some things simply refuse to be cloned:




  • ❌ Functions (they have commitment issues)

  • ❌ DOM nodes (use cloneNode)

  • ❌ Symbols

  • WeakMap, WeakSet



Try cloning these and JavaScript will politely throw a DataCloneError instead of silently ruining your data.


Honestly? We appreciate the honesty.









structuredClone vs Spread Operator 🥊






const original = { a: { b: 1 } };

const shallow = { ...original };
const deep = structuredClone(original);

shallow.a.b = 2;

console.log(original.a.b); // 2 ❌
deep.a.b = 3;
console.log(original.a.b); // still 2 ✅






Spread operator:




“I’ll copy the top layer and hope for the best.”




structuredClone:




“I’ll copy everything. Thoroughly.”










Performance: Should I Worry?




  • Faster than JSON.parse(JSON.stringify())

  • Optimized by modern JS engines

  • Safe for state cloning and message passing



⚠️ Just don’t clone massive objects in tight loops unless you enjoy performance reviews.









Where You’ll Actually Use This




  • React state updates (immutability without headaches)

  • Redux / Zustand / any state manager

  • Web Workers

  • Undo / redo features

  • Caching snapshots

  • “Why did this mutate?” bug prevention









Browser & Runtime Support 🌍



Good news:




  • Modern browsers ✅

  • Node.js 17+ ✅

  • Deno, Bun ✅



No polyfills. No drama.









Final Thoughts 💭



structuredClone() is:




  • ✅ Native

  • ✅ Safe

  • ✅ Deep

  • ✅ Honest about errors



If you’re still using JSON.parse(JSON.stringify()), it’s okay.


We all grow. 😄




Modern JavaScript has given us a proper deep clone.


Let’s actually use it.







💬 Have you been betrayed by shallow copies before?


Share your cloning horror stories in the comments!

Ähnliche Beiträge
🔍 Verwandte News

Auch interessante Nachrichten structuredClone() — The Deep Copy Hero JavaScript Deserved 🦸‍♀️

Thematisch verwandte Begriffe: structuredClone, Deep, Copy, Hero · 6 Treffer

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Zum Aktualisieren ziehen
ZERO-DAY CVE-2026-17636 | IBM Financial Transaction Manager (FTM) for RedHat OpenShift could allow…
Advisory →
TTS Reader • tsecurity.de Voice
tsecurity.de Icon
tsecurity.de App
Offline-Lesen, Eilmeldungen & 0ms Ladezeit

Installiere tsecurity.de direkt auf deinen Home-Bildschirm für das ultimative Vollbild-Magazinerlebnis ohne Browser-Leisten.

Nächster Beitrag
Themen-Radar & Intelligence Matrix
Echtzeit-Taxonomie nach Angriffsvektoren & Plattformen

tsecurity.de Live Threat Radar

🔴 LIVE RADAR
MONITORING
AKTIV
CVE-DATENBANK
LIVE
🔍
Community Radar & Live Chat
Sentinel Bot online • Live-Stream
Dein Cluster: Security Explorer
Match:
lädt…
Verbindung zum Community-Stream wird aufgebaut...
Bearbeitungsmodus — Senden überschreibt deine Nachricht
Community-Puls — was gerade passiert
lädt…
Aktivitäten deiner Analysten
lädt…
Neues Thema oder Eilmeldung einreichen

Reiche interessante Links, Zero-Days oder Debatten ein. Die Community entscheidet per Upvote über die Veröffentlichung.

Heiß diskutierte Einreichungen
🔖 Gespeicherte Artikel
📂 Keine gespeicherten Artikel vorhanden.
Zurück Ziehen Vor
Links: vorheriger Artikel Rechts: nächster Artikel unten: schließen
News NIS-2 Frühwarnung Tier-1 Intel ⏱️ 3 Min vor 10 Min
Artikeldaten werden geladen...

Zurück: vorheriger Vor: nächster
↗ Original-Quelle
Social Reaktionen Deine Reaktion zählt
Einstufung & Relevanz-Poll 0 Stimmen
In sozialen Netzwerken teilen 1-Klick