Загрузка видео...

Не удалось загрузить видео

На главную

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 просмотров • 3 лет назад •via X (Twitter)

Комментарии: 10

Фото профиля Steve (Builder.io)
Steve (Builder.io)3 лет назад

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

Фото профиля Luke Edwards
Luke Edwards3 лет назад

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
Jarred Sumner3 лет назад

ugh we still need to implement this in bun

Фото профиля Jesse Pence
Jesse Pence3 лет назад

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)
Steve (Builder.io)3 лет назад

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
Isaac Way3 лет назад

Js has the most random standard library

Фото профиля Okiki Ojo
Okiki Ojo3 лет назад

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
Conny Brunnkvist3 лет назад

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

Фото профиля RodAvi
RodAvi3 лет назад

Awesome tip Thanks !!!!

Фото профиля Tomas Pi Puig
Tomas Pi Puig3 лет назад

Actually not bad..

Похожие видео