News for hackers. Stuff that matters.
Re:Deep Cloning Objects in JavaScript, the Modern Way by holoduke on Thursday December 21, 2023 @07:05PM (#38728981)
An object containing just data for sure having lots of usecases. Like i.e undo/redo. But deep cloning would be as simple as json.parse(json.stringify(object))
Re:Deep Cloning Objects in JavaScript, the Modern Way by chatmasta on Thursday December 21, 2023 @07:13PM (#38729062)
Yeah, agreed. And in that case you should treat the "data object" as opaque, in which case it should be sufficient to pass it by reference. Hence, if you're reaching for deepClone, it's a code smell - why can't you pass the reference? Are you mutating the data object somewhere that you shouldn't be?