Video není dostupné.
Omlouváme se.

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

Sdílet
Vložit
  • čas přidán 19. 08. 2024

Komentáře • 45

  • @jasonrm999
    @jasonrm999 Před rokem +64

    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,

  • @universecode1101
    @universecode1101 Před rokem +2

    Great and important topic on JavaScript James. Master JS is so important 🙂

  • @colinmarshall6634
    @colinmarshall6634 Před rokem +2

    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 Před rokem

      Luckily, Node 18 is LTS for a year now

    • @colinmarshall6634
      @colinmarshall6634 Před rokem

      ​@@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.

    • @deckyfiyemonda9893
      @deckyfiyemonda9893 Před rokem

      @@dinoscheidt but AFAIK, node version higher than 16 is breaking react and react native.

  • @AjayKumar-hg2je
    @AjayKumar-hg2je Před rokem

    Thank you so much. This is problem that I faced last week, made me worth following you :p

  • @sateeshnaidu900
    @sateeshnaidu900 Před rokem

    Thanks for sharing the info James

  • @manojjangid6213
    @manojjangid6213 Před rokem

    Thanks for this valuable code guide. 👍

  • @christopheanfry2425
    @christopheanfry2425 Před rokem

    Always learning interesting and useful features. I didn’t know that spread operator was not going deep. Thanks 🙏

  • @Joe-SoftwareEngineer
    @Joe-SoftwareEngineer Před rokem

    Love it! Finally a real native way to do a deep copy! 👍

  • @aymanechaaba
    @aymanechaaba Před rokem

    Thank You!! ❤❤

  • @mohsenkhashei5472
    @mohsenkhashei5472 Před rokem

    thanks James🤞

  • @deckyfiyemonda9893
    @deckyfiyemonda9893 Před rokem +1

    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?

  • @__jake.m
    @__jake.m Před rokem

    Thank you so much for this, James! You really helped a lot.

  • @developerpranav
    @developerpranav Před rokem

    Another helpful topic, great video!

  • @dominuskelvin
    @dominuskelvin Před rokem

    Amazing video. So much good APIs ☺️

  • @rara901
    @rara901 Před rokem +1

    What is your theme?

  • @dorian7215
    @dorian7215 Před rokem

    Great info. Thank you.

  • @iUmerFarooq
    @iUmerFarooq Před rokem

    Thank you 😊

  • @pakkavideos
    @pakkavideos Před rokem

    If object has function it copy that also?

  • @The_SSS
    @The_SSS Před rokem +1

    I recommend using rust jk

  • @NeverCodeAlone
    @NeverCodeAlone Před rokem

    Very good thx a lot

  • @everusa15
    @everusa15 Před rokem +2

    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.

  • @michaelkrison
    @michaelkrison Před rokem

    hey James, which theme are you using?

  • @shobhitkumar_shorts
    @shobhitkumar_shorts Před rokem

    Still need to depend upon third party libraries, as structured clones do not work in case of function

  • @astb01
    @astb01 Před rokem

    It would be cool if they extended the spread operator with an argument such as {….foo, 2} meaning copy two levels deep 🤔

  • @willyhorizont8672
    @willyhorizont8672 Před rokem

    Shoot I use spread operator all of my codes! Does this work with array of object too??

    • @Cognitoman
      @Cognitoman Před měsícem

      Spread operator doesn’t do nested copies

  • @user-lq7xz1th4x
    @user-lq7xz1th4x Před rokem +1

    Take care of yourself

  • @AlaaBallout
    @AlaaBallout Před rokem

    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 .

  • @talk2MeGooseman
    @talk2MeGooseman Před rokem

    "Not IE11, that's a separate conversation".... When the E11 conversation going ot happen? ( O _ O )

    • @vickmackey24
      @vickmackey24 Před rokem

      No one uses that anymore. Microsoft dropped support for it some time ago. It's a waste of time to even discuss it.

  • @orbitory7936
    @orbitory7936 Před rokem

    Don't use if your users have older chrome versions or other browsers

  • @arunkaiser
    @arunkaiser Před rokem

    🥇 💬

  • @dinckelman
    @dinckelman Před rokem +1

    Goodbye lodash

    • @Cognitoman
      @Cognitoman Před měsícem

      Nope still need it, this won’t work for for every case, if it has a class, function or symbol

  • @bmp713
    @bmp713 Před 11 měsíci

    This is absurd to have to jump through so many hoops just to copy an object. It should absolutely be a native JS function.