5 ms·
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 ho
by jwalton 3y ago
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/baseClone.ts https://github.com/lodash/lodash/blob/main/src/.internal/bas...
- baq 3y agoWould it be shorter if it didn’t, though?
- addandsubtract 3y agoThe 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.
- qayxc 3y agoGlimpsing 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.
- mishac 3y agoUnnecessary _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