3 ms·
To those saying "Why bother when there is ES5?", don't forget Lo-Dash/Underscore are more than the handful of ES5 methods. They each contain well over 100 utili
by jdd 13y ago
To those saying "Why bother when there is ES5?", don't forget Lo-Dash/Underscore are more than the handful of ES5 methods. They each contain well over 100 utility methods for everything from iterating arrays and objects, to templates, and even function composition.
A lib can offer leeway and enhancements over bare metal language APIs. For example, in Lo-Dash you can do callback shorthands like `_.every(buttons,'disabled')` instead of `buttons.every(function(button){return button.disabled});`.
Lo-Dash's methods are more consistent than shims and in many cases faster than their ES5 counterparts. Shims have to follow the language specification which means they have a lot more overhead than their
Lo-Dash equivalents making them slower in older environments where performance is already an issue. Shims also fail to address engine issues like how IE<9 treats arrays like `[1, undefined, 3]` as sparse when no other engine does. Lo-Dash smooths over these issues by treating all arrays as dense and gets better performance in the process.
Utility libs, like Lo-Dash, can give you more consistency, generally better performance, and more features than their ES5 counterparts.
- mathias 13y agoAnother example is: _.forEach(array, function(item) { doSomething(); if (condition) { // exits iteration early return false; } }); This is just not possible with native `Array#forEach` – you’d have to use a plain `for` loop with a conditional `break` statement instead, or rewrite your code to use `Array#some`.