Re:Deep Cloning Objects in JavaScript, the Modern Way
by toddmorey on Thursday December 21, 2023 @06:53PM
(#38728880)
I cannot believe lodash cloneDeep (just the one function) is 17.4kb minified!
[ Parent
| on HN ]
Re:Deep Cloning Objects in JavaScript, the Modern Way
by jwalton on Thursday December 21, 2023 @07:06PM
(#38728994)
A lot of Lodash functions are implemented as combinations of other Lodash functions, so importing a single function actually imports half of Lodash under the hood:
https://github.com/lodash/lodash/blob/main/src/.internal/bas...
Re:Deep Cloning Objects in JavaScript, the Modern Way
by baq on Friday December 22, 2023 @03:10AM
(#38732076)
Would it be shorter if it didn’t, though?
Re:Deep Cloning Objects in JavaScript, the Modern Way
by addandsubtract on Friday December 22, 2023 @05:58AM
(#38733011)
The expectation is that you import the whole library and not just one function. At which point, lodash is smaller than if each function was implemented separately.
Re:Deep Cloning Objects in JavaScript, the Modern Way
by qayxc on Friday December 22, 2023 @06:05AM
(#38733049)
Glimpsing at the source code - yes, definitely.
For example, the code imports "copyArray", a 9LoC function that does exactly the same as the built-in Array.slice() would do.
Same goes for other imported helpers like "arrayEach", which could be replaced by the built-in Array.every().
It's basically a bunch of unnecessary polyfills for built-ins.
Re:Deep Cloning Objects in JavaScript, the Modern Way
by mishac on Monday December 25, 2023 @02:45PM
(#38765491)
Unnecessary _now_ perhaps, but not unnecessary when lodash was written. In 2009, when underscore.js came out (from which lodash was a fork) Array.every() was not something you could rely on. Chrome just came out a year earlier (and didn't support Array.every until version 4) and half the world was on IE 6-7-8
Re:Deep Cloning Objects in JavaScript, the Modern Way
by nobleach on Friday December 22, 2023 @08:03AM
(#38733719)
I actively fight for removal of lodash in every frontend codebase I encounter. The cost is just too much. Often I run into developers who tell me there's some sort of webpack plugin to treeshake all the `import _ from 'lodash';` nonsense. The truth is, when we run a bundle analyzer, it's still one of the biggest bloaters. Webpack is also becoming less common in newer codebases. The point is, while it provides a ton of convenience methods, there is a cost.