Video wird geladen...

Video konnte nicht geladen werden

Zur Startseite

This is one you need to know. JS has a built-in function for deep cloning objects called `structuredClone`, which can handle: 😍 Deeply nested objects and arrays 🌎 Many types, like Date, Set, Map, etc ➰ Circular references More in my latest article:

551,315 Aufrufe • vor 3 Jahren •via X (Twitter)

10 Kommentare

Profilbild von Steve (Builder.io)
Steve (Builder.io)vor 3 Jahren

More on what `structuredClone` can do, and how it compares to alternatives, in my latest post:

Profilbild von Luke Edwards
Luke Edwardsvor 3 Jahren

Unfortunately it’s comparatively pretty slow & relatively new so a significant portion of audiences can’t support it. is 500b at heaviest and extremely fast.

Profilbild von Jarred Sumner
Jarred Sumnervor 3 Jahren

ugh we still need to implement this in bun

Profilbild von Jesse Pence
Jesse Pencevor 3 Jahren

I see the double JSON move in so many old code bases. Would this be worthy of a pull request or would I probably just annoy the maintainers?

Profilbild von Steve (Builder.io)
Steve (Builder.io)vor 3 Jahren

Good Q. There are some minor but notable differences, like JSON is a little faster in some cases, and structureClone will throw errors for some things JSON won’t and visa versa, and handling some types like undefined are different. Probably safest to not semi blindly swap

Profilbild von Isaac Way
Isaac Wayvor 3 Jahren

Js has the most random standard library

Profilbild von Okiki Ojo
Okiki Ojovor 3 Jahren

structuredClone also supports ArrayBuffers, Streams, etc... but, unfortunately you have to manually list them out as transferable objects for it to work, that's where `transferables` comes in, it makes it fast and easy to use transferable objects

Profilbild von Conny Brunnkvist
Conny Brunnkvistvor 3 Jahren

Thanks for highlighting this. Reading up, I found these note on its limitations interesting too:

Profilbild von RodAvi
RodAvivor 3 Jahren

Awesome tip Thanks !!!!

Profilbild von Tomas Pi Puig
Tomas Pi Puigvor 3 Jahren

Actually not bad..

Ähnliche Videos