4 ms·
This looks like a good book but boy, is JavaScript convoluted. Not bashing it. Just read the chapters about shallow and deep copies. https://exploringjs.com/de
by geonic 5y ago
This looks like a good book but boy, is JavaScript convoluted. Not bashing it. Just read the chapters about shallow and deep copies.
https://exploringjs.com/deep-js/ch_copying-objects-and-arrays.html https://exploringjs.com/deep-js/ch_copying-objects-and-array...
- mikewhy 5y agoIsn't shallow vs deep copying a thing in most languages?
- geonic 5y agoIt is. JavaScript seems to have quite a few ways of getting it wrong though.
- kdmccormick 5y agoFortunately, it seems to be convoluted as a result of its underlying simplicity, perhaps? The reason the article you linked is so long (instead of just being the standard OOP shallow- vs deep-copy disclaimer) seems to be because JS objects and classes are just dictionaries (in the Python sense of the word) with certain magic fields to control dispatch, inheritance, etc. The docs need to take care to explain how certain operations interact with those magic fields. So, still convoluted, but IMO better than if it were convoluted because everything was a built-in special case under the hood. At least that's my impression as someone who doesn't write a lot of JS. Happy to be corrected.
- adt2bt 5y agoThat's also my impression as someone who used to write a lot of JS - everything is either a value, dict or array, and once you learn some guardrails on how you write JS code (in your words, 'explain how certain operations interact with those magic fields'), it becomes remarkably nice to use.
- stupidcar 5y agoDo you have any empirical evidence it is more convoluted than equivalent popular languages?
- geonic 5y agoI wasn't saying it is more convoluted than other languages. I just found it interesting that there are so many idiosyncrasies and gotchas.