Reference
Shared vocabulary for this workspace. Lessons stick to these meanings.
postMessage, BroadcastChannel, IndexedDB, History state,
and structuredClone().
Copies data, not behavior.
structuredClone(value) or
structuredClone(value, { transfer }). Reach for it when
you need a same-realm snapshot. Many APIs already clone for you.
{...obj}, Object.assign, array
slice). Nested objects stay shared.
JSON.parse(JSON.stringify(value)). Produces a
JSON document in the middle — not a faithful clone.
Date becomes a string; Map/Set
become {}; cycles and BigInt throw;
functions and undefined are dropped or become
null.
ArrayBuffer, MessagePort,
ImageBitmap. After transfer, the source is
detached.
structuredClone(value, { transfer }) or
postMessage(value, transfer). It is not a second
payload — listed objects must also appear in
value, or they detach with nowhere to land.
ArrayBuffer symptom: byteLength === 0.
A detached buffer cannot be cloned or transferred again.
postMessage, BroadcastChannel, IndexedDB put/get, and
history.pushState are implicit. Don’t
structuredClone first unless you need a snapshot for
another reason.
structuredClone().
Date stays a Date), with new identity.
Cycles keep their self-links via the
memory map.
Object.prototype) holding enumerable own
data only. Methods, private fields, and the original
prototype are gone. This is what happens to class instances.
DataCloneError.
Functions, DOM nodes, symbol values, Promise,
WeakMap, and Proxy land here.
Object.keys / for…in. Structured clone
walks these, then reads them with [[Get]] (getters
run). Symbol keys are dropped.