3 ms·
I think all else being equal (e.x. assuming sufficient browser support or polyfilling), people should prefer using standard / built-in functions, many of which
by tlrobinson 7y ago
I think all else being equal (e.x. assuming sufficient browser support or polyfilling), people should prefer using standard / built-in functions, many of which have been added to JavaScript since Underscore was popularized.
However, I don't necessarily agree with this approach of providing snippets for functions which aren't implemented natively. Underscore and Lodash likely have better implementations and much more testing. If you're concerned about bundle size, use tree shaking or individual function imports.
I think one exception to this is if you are writing a library and want to keep dependencies to an absolute minimum.
- mcphage 7y ago> people should prefer using standard / built-in functions I get that, but that's not what this list is: this list is re-implementing lodash / underscore using built-in functions. They're not a 1-for-1 replacement, they're complex implementations which may or may not be correct or efficient. If their solution for replacing _.chunk(...) was some built-in Array.chunk(...) or something, that would be fine. But instead, it's this: > const chunk = (input, size) => { > return input.reduce((arr, item, idx) => { > return idx % size === 0 > ? [...arr, [item]] > : [...arr.slice(0, -1), [...arr.slice(-1)[0], item]]; > }, []); > }; That's definitely worse than using lodash.
- tlrobinson 7y agoThat's exactly what I said in my second paragraph...
- mcphage 7y agoAh, you did. Sorry about that, you’ve caught me running my mouth off before I finish reading.