2023-01-28
https://www.builder.io/blog/structured-clone
なるほど、使っていこう。
$ deno
Deno 1.29.4
exit using ctrl+d, ctrl+c, or close()
REPL is running with all permissions allowed.
To specify permissions, run `deno repl` with allow flags.
> const a = {foo: "bar"}
undefined
> const b = structuredClone(a)
undefined
> console.log(JSON.stringify(a))
{"foo":"bar"}
undefined
> console.log(JSON.stringify(b))
{"foo":"bar"}
undefined
> a.foo = "baz"
"baz"
> console.log(JSON.stringify(a))
{"foo":"baz"}
undefined
> console.log(JSON.stringify(b))
{"foo":"bar"}
undefined
モダンブラウザは全て対応済み。
https://caniuse.com/mdn-api_structuredclone