4 ms·
Wow, that's nostalgic. I remember implementing and writing about deepCopy() in JavaScript over 14 (!) years ago[1]. If you read the OP article and were left won
by olooney 3y ago
Wow, that's nostalgic. I remember implementing and writing about deepCopy() in JavaScript over 14 (!) years ago[1]. If you read the OP article and were left wondering how such an algorithm actually works, that old article explains it in some detail. The basic idea is still the same; only the handling of edge cases introduced by newer language features is different.
That implementation eventual became obsolete (although it still runs on basic object types) because of newer features being added to the JavaScript language, and by then other implementations were available. It's great to hear a de facto standard is emerging, even if hasn't made it into ECMAScript standard yet[2]. It sounds like the same edge cases are still causing problems. I think if a language is to ever offer really great support for deep copy it must be designed into the language as a first-class feature from the get go.
[1]: https://www.oranlooney.com/post/deep-copy-javascript/ https://www.oranlooney.com/post/deep-copy-javascript/
[2]: https://es.discourse.group/t/structuredclone-as-ecmascript-standard/1661 https://es.discourse.group/t/structuredclone-as-ecmascript-s...
- dgreensp 3y agoWell it sounds like it’s a web standard and clones a heck ton of browser objects that ECMAScript wouldn’t be able to require it to clone. But yes, I suppose requiring it to exist and work on non-host objects in ECMAScript would be ideal!