structuredClone, finally, in every browser that matters

Deep copying had been a JSON round trip, which loses Dates, Maps, Sets, RegExps, undefined and every cycle.

JSON.parse(JSON.stringify({ d: new Date(), m: new Map() }))
// { d: '2022-05-14T09:41:02.104Z', m: {} }

structuredClone({ d: new Date(), m: new Map() })
// { d: Date, m: Map }

// what it still cannot clone:
//   functions, DOM nodes, class instances (the prototype
//   is lost — you get a plain object), symbols, getters

Losing the prototype is the limitation that matters for anything class-based: a cloned instance is a plain object with the same data and none of the methods, which fails later rather than at the clone. It is also synchronous and can be slow on a large structure, so it is not free in a hot path.