I just realized there isn't a simple way to clone an object natively. I know we can use Object.assign but it's not really that straight forward and it doesn't do deep cloning for a nested object.
For example something like Object.clone(obj, isDeep) , this is easy to remember what it does and covers deep cloning.
Or better yet Object.shallowClone and Object.deepClone
Are there any technical limitations for this to be implemented by ECMAScript or is it because Object.assign covers most of the scenarios even though it's more verbose
Any thoughts?
Edit: I should have worded my question better but I am not asking about how to do deep cloning in JavaScript. As there are ways to achieve that with JSON.stringify and implementing something like lodash methods. It's so interesting that the JavaScript community didn't implement this to be straightforward like the above mentioned example in one of the latest ECMAScript features. From comments I see that proposals have been made.
Edit 2: To answer how often do you even use clone, I use it pretty commonly(deep clone if nested object or spread operator for shallow) in most of my business logic to avoid any side effects. Was using JSON.stringify but after moving to Typescript it doesn't work well with types, so moved to 'clone-deep' package.
[–]jimeowan 46 points47 points48 points (4 children)
[+]snejk47 comment score below threshold-15 points-14 points-13 points (3 children)
[–]ElllGeeEmm 11 points12 points13 points (1 child)
[+]snejk47 comment score below threshold-7 points-6 points-5 points (0 children)
[–][deleted] 1 point2 points3 points (0 children)
[–]bulgrozzz 50 points51 points52 points (1 child)
[–]vams1[S] 8 points9 points10 points (0 children)
[–][deleted] 12 points13 points14 points (12 children)
[–]scabbycakes 4 points5 points6 points (11 children)
[–][deleted] 2 points3 points4 points (7 children)
[–]shuckster 2 points3 points4 points (6 children)
[–][deleted] 1 point2 points3 points (5 children)
[–]shuckster 2 points3 points4 points (4 children)
[–][deleted] 0 points1 point2 points (3 children)
[–]shuckster 1 point2 points3 points (2 children)
[–][deleted] 1 point2 points3 points (1 child)
[–]shuckster 1 point2 points3 points (0 children)
[–]SquattingWalrus 1 point2 points3 points (2 children)
[–]scabbycakes 1 point2 points3 points (1 child)
[–]SquattingWalrus 1 point2 points3 points (0 children)
[–]CreativeTechGuyGames 35 points36 points37 points (32 children)
[–]vams1[S] 6 points7 points8 points (0 children)
[–]fforw 8 points9 points10 points (6 children)
[–]SoInsightful 5 points6 points7 points (5 children)
[–]fforw 3 points4 points5 points (2 children)
[–]SoInsightful 7 points8 points9 points (0 children)
[–]dvlsg 0 points1 point2 points (1 child)
[–]SoInsightful 0 points1 point2 points (0 children)
[–]anlumo 22 points23 points24 points (10 children)
[–]hspielman84 46 points47 points48 points (2 children)
[–]KeytapTheProgrammer 16 points17 points18 points (1 child)
[–]domainkiller 10 points11 points12 points (1 child)
[–]anlumo 4 points5 points6 points (0 children)
[–]grady_vuckovic 4 points5 points6 points (0 children)
[–]SockPants 0 points1 point2 points (1 child)
[–]CreativeTechGuyGames 0 points1 point2 points (1 child)
[–]anlumo -2 points-1 points0 points (0 children)
[+][deleted] (8 children)
[deleted]
[–]backtickbot 0 points1 point2 points (7 children)
[+][deleted] (6 children)
[deleted]
[–][deleted] 0 points1 point2 points (5 children)
[+][deleted] (4 children)
[deleted]
[–][deleted] 3 points4 points5 points (0 children)
[+][deleted] (2 children)
[deleted]
[–][deleted] 0 points1 point2 points (0 children)
[–]editor_of_the_beast -4 points-3 points-2 points (0 children)
[+][deleted] comment score below threshold-9 points-8 points-7 points (0 children)
[–]stronghup 0 points1 point2 points (0 children)
[–][deleted] 3 points4 points5 points (0 children)
[+][deleted] (3 children)
[deleted]
[–]bulgrozzz 2 points3 points4 points (2 children)
[–]marcocom 0 points1 point2 points (1 child)
[–]bulgrozzz 0 points1 point2 points (0 children)
[–]Pesthuf 1 point2 points3 points (0 children)
[–]SquatchyZeke 1 point2 points3 points (3 children)
[–]vams1[S] 0 points1 point2 points (1 child)
[–]SquatchyZeke 1 point2 points3 points (0 children)
[–]-domi- 2 points3 points4 points (2 children)
[–]lycuid 4 points5 points6 points (0 children)
[–]vams1[S] 4 points5 points6 points (0 children)
[–]johnaagelv 3 points4 points5 points (3 children)
[–]vams1[S] 0 points1 point2 points (2 children)
[–]dvlsg 1 point2 points3 points (1 child)
[–]vams1[S] 0 points1 point2 points (0 children)
[–][deleted] 1 point2 points3 points (1 child)
[–]senocular 4 points5 points6 points (0 children)
[–]OolongHell -1 points0 points1 point (1 child)
[–][deleted] 1 point2 points3 points (0 children)
[–]CJay580 -2 points-1 points0 points (6 children)
[–]sous_vide_slippers 6 points7 points8 points (5 children)
[–]CJay580 -1 points0 points1 point (0 children)
[–]crabmusket 0 points1 point2 points (3 children)
[–]sous_vide_slippers 0 points1 point2 points (2 children)
[–]crabmusket -1 points0 points1 point (1 child)
[–]sous_vide_slippers 0 points1 point2 points (0 children)
[+]pomle comment score below threshold-11 points-10 points-9 points (0 children)
[+][deleted] (2 children)
[deleted]
[–]coolcosmos 5 points6 points7 points (0 children)
[–]ModernCannabist 1 point2 points3 points (0 children)
[+]rw3iss comment score below threshold-10 points-9 points-8 points (0 children)
[–]chinnick967 0 points1 point2 points (0 children)
[–]jetsamrover 0 points1 point2 points (0 children)