How To Make a DEEP Copy in JavaScript (No Libraries and No Hacks!)

  Рет қаралды 16,227

James Q Quick

James Q Quick

Күн бұрын

Пікірлер: 46
@jasonrm999
@jasonrm999 Жыл бұрын
StructuredClone is actually a web API (like setTimeout, etc), not part of JS. If the object contains methods, structuredClone will throw an exception, the JSON hack will strip them for the new object without erroring,
@ongke3655
@ongke3655 Жыл бұрын
Really? That's suck
@purelianii
@purelianii Жыл бұрын
it also throws an error on proxy objects
@deckyfx2188
@deckyfx2188 Жыл бұрын
What version of NodeJS does it support? Also what about an Instance object? not JSON object but an object yielded by `new Class()`, and does it also clone the object methods?
@sateeshnaidu900
@sateeshnaidu900 Жыл бұрын
Thanks for sharing the info James
@universecode1101
@universecode1101 Жыл бұрын
Great and important topic on JavaScript James. Master JS is so important 🙂
@michaelkrison
@michaelkrison Жыл бұрын
hey James, which theme are you using?
@AjayKumar-hg2je
@AjayKumar-hg2je Жыл бұрын
Thank you so much. This is problem that I faced last week, made me worth following you :p
@manojjangid6213
@manojjangid6213 Жыл бұрын
Thanks for this valuable code guide. 👍
@pakkavideos
@pakkavideos Жыл бұрын
If object has function it copy that also?
@developerpranav
@developerpranav Жыл бұрын
Another helpful topic, great video!
@dorian7215
@dorian7215 Жыл бұрын
Great info. Thank you.
@Joe-SoftwareEngineer
@Joe-SoftwareEngineer Жыл бұрын
Love it! Finally a real native way to do a deep copy! 👍
@mohsenkhashei5472
@mohsenkhashei5472 Жыл бұрын
thanks James🤞
@christopheanfry
@christopheanfry Жыл бұрын
Always learning interesting and useful features. I didn’t know that spread operator was not going deep. Thanks 🙏
@colinmarshall6634
@colinmarshall6634 Жыл бұрын
Great video! IE11 was killed off anyway so this is basically full support. However, it was only added to Node 17 so it won't work if you're on an older version of Node.
@dinoscheidt
@dinoscheidt Жыл бұрын
Luckily, Node 18 is LTS for a year now
@colinmarshall6634
@colinmarshall6634 Жыл бұрын
​@@dinoscheidt I get it, but that doesn't mean everyone's company does. There's plenty of reasons for people to be using older versions.
@deckyfx2188
@deckyfx2188 Жыл бұрын
@@dinoscheidt but AFAIK, node version higher than 16 is breaking react and react native.
@aymanechaaba
@aymanechaaba Жыл бұрын
Thank You!! ❤❤
@__jake.m
@__jake.m Жыл бұрын
Thank you so much for this, James! You really helped a lot.
@JamesQQuick
@JamesQQuick Жыл бұрын
So glad to hear that!
@dominuskelvin
@dominuskelvin Жыл бұрын
Amazing video. So much good APIs ☺️
@iUmerFarooq
@iUmerFarooq Жыл бұрын
Thank you 😊
@rara901
@rara901 Жыл бұрын
What is your theme?
@willyhorizont8672
@willyhorizont8672 Жыл бұрын
Shoot I use spread operator all of my codes! Does this work with array of object too??
@Cognitoman
@Cognitoman 5 ай бұрын
Spread operator doesn’t do nested copies
@shobhitkumar_shorts
@shobhitkumar_shorts Жыл бұрын
Still need to depend upon third party libraries, as structured clones do not work in case of function
@NeverCodeAlone
@NeverCodeAlone Жыл бұрын
Very good thx a lot
@DigitalAlchemyst
@DigitalAlchemyst 4 ай бұрын
Confirmed structed clone handles circular references
@astb01
@astb01 Жыл бұрын
It would be cool if they extended the spread operator with an argument such as {….foo, 2} meaning copy two levels deep 🤔
@everusa15
@everusa15 Жыл бұрын
Pretty good support ?! I would say no. Check the table for browser compatibility, it kinda sucks. I think the hack method is the best, 2nd option you can use a 3rd party lib. But who am I ? Just a petty sr developer with many years of experience that knows: compatibility is a "beach" and frugality is very important.
@talk2MeGooseman
@talk2MeGooseman Жыл бұрын
"Not IE11, that's a separate conversation".... When the E11 conversation going ot happen? ( O _ O )
@vickmackey24
@vickmackey24 Жыл бұрын
No one uses that anymore. Microsoft dropped support for it some time ago. It's a waste of time to even discuss it.
@AlaaBallout
@AlaaBallout Жыл бұрын
Javascript is just a weird language, I feel like it try to act like a programming language but we are obligated to use it since the browser work with js .
@The_SSS
@The_SSS Жыл бұрын
I recommend using rust jk
@orbitory7936
@orbitory7936 Жыл бұрын
Don't use if your users have older chrome versions or other browsers
@Александр-ч4п5ъ
@Александр-ч4п5ъ Жыл бұрын
Take care of yourself
@bmp713
@bmp713 Жыл бұрын
This is absurd to have to jump through so many hoops just to copy an object. It should absolutely be a native JS function.
@arunkaiser
@arunkaiser Жыл бұрын
🥇 💬
@dinckelman
@dinckelman Жыл бұрын
Goodbye lodash
@Cognitoman
@Cognitoman 5 ай бұрын
Nope still need it, this won’t work for for every case, if it has a class, function or symbol
Top 5 Async Mistakes for JavaScript Beginners (Don’t make these!)
15:11
I Paid Game Developers on Fiverr to Make the Same Game
9:49
BadGameDev
Рет қаралды 3,4 МЛН
Sigma Kid Mistake #funny #sigma
00:17
CRAZY GREAPA
Рет қаралды 30 МЛН
人是不能做到吗?#火影忍者 #家人  #佐助
00:20
火影忍者一家
Рет қаралды 20 МЛН
The JavaScript Spread Operator  -  One Thing You DIDN'T KNOW!
9:20
James Q Quick
Рет қаралды 26 М.
Use Maps more and Objects less
5:45
Steve (Builder.io)
Рет қаралды 103 М.
How I learned to code and landed a job (no CS degree!)
6:55
Coder Coder
Рет қаралды 574 М.
5 Tips for Writing BETTER For Loops in JavaScript
16:15
James Q Quick
Рет қаралды 70 М.
JavaScript Visualized - Event Loop, Web APIs, (Micro)task Queue
12:35
I tried 8 different Postgres ORMs
9:46
Beyond Fireship
Рет қаралды 443 М.
I Waited 15 Years For These New Array Methods
8:11
Web Dev Simplified
Рет қаралды 223 М.
I Tried Astro Build and I LOVE IT - 5 Reasons You Will TOO!
12:48
James Q Quick
Рет қаралды 39 М.
Real 10x Programmers Are SLOW To Write Code
14:51
Thriving Technologist
Рет қаралды 69 М.