Video yükleniyor...

Video Yüklenemedi

Ana Sayfaya Dön

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 görüntüleme • 3 yıl önce •via X (Twitter)

10 Yorum

Steve (Builder.io) profil fotoğrafı
Steve (Builder.io)3 yıl önce

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

Luke Edwards profil fotoğrafı
Luke Edwards3 yıl önce

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.

Jarred Sumner profil fotoğrafı
Jarred Sumner3 yıl önce

ugh we still need to implement this in bun

Jesse Pence profil fotoğrafı
Jesse Pence3 yıl önce

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?

Steve (Builder.io) profil fotoğrafı
Steve (Builder.io)3 yıl önce

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

Isaac Way profil fotoğrafı
Isaac Way3 yıl önce

Js has the most random standard library

Okiki Ojo profil fotoğrafı
Okiki Ojo3 yıl önce

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

Conny Brunnkvist profil fotoğrafı
Conny Brunnkvist3 yıl önce

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

RodAvi profil fotoğrafı
RodAvi3 yıl önce

Awesome tip Thanks !!!!

Tomas Pi Puig profil fotoğrafı
Tomas Pi Puig3 yıl önce

Actually not bad..

Benzer Videolar