7 ms·
Next to jQuery, Underscore is my most-used JS library. Makes scripting client-side behavior so much more pleasant.
by luigi 16y ago
Next to jQuery, Underscore is my most-used JS library. Makes scripting client-side behavior so much more pleasant.
- shawndumas 16y ago"It's the tie to go along with jQuery's tux."[1] ----- [1]: http://documentcloud.github.com/underscore/ http://documentcloud.github.com/underscore/
- chewbranca 16y agoI don't understand this statement. Initially when I saw underscore.js a few weeks ago, I was under the impression it was a light weight js library for when you didn't want to use jquery or something even heavier. Do you use this in conjunction with jquery? Could someone please explain the use case for this library as their is a fair bit of duplication between this and jquery.
- jashkenas 16y agoUnderscore is intended to fit in nicely alongside jQuery -- in the handful of places where the two overlap (map, each, bind), Underscore delegates to the native browser implementations, providing quite a substantial performance boost over the jQuery versions. There is a benchmark script at the bottom of this page, and you can run it in your browser to see the difference: http://documentcloud.github.com/underscore/test/test.html http://documentcloud.github.com/underscore/test/test.html In general, Underscore is intended for logic and data manipulation, and jQuery handles the DOM and Ajax calls.
- chewbranca 16y agoThank you for clarifying, I appreciate it. There are some very nice data manipulation functions in underscore, and its speed is impressive. I will definitely look into it more.
- pyronicide 16y agoTotally agreed. Underscore has quickly become the one js library that I cannot live without, no matter what.
- steadicat 16y agoI tweeted this yesterday: Why does Underscore.js get the order of arguments wrong? There’s a reason why it’s map(fn, l), not map(l, fn). And the reason is currying. I find that very annoying for the kind of functional programming I tend to do. For that reason alone I started looking at Wu.js instead. Am I missing something?
- shawndumas 16y agoI mainly use Object-Oriented Style[1]. ----- http://documentcloud.github.com/underscore/#styles http://documentcloud.github.com/underscore/#styles
- steadicat 16y agoCan you do things like var sum = curry(reduce, add); with the OO style? Am I wrong in thinking that this kind of currying is one of the fundamental building blocks of functional programming?
- shawndumas 16y agoDo you mean like this? var sum = function (a) { return _(a).reduce(function (m, n) { return m + n; }, 0); }; sum([1,2,3,4,5,6,7,8,9]); // => 45 Or am I not getting you?
- steadicat 16y agoThat's one way to do it, but you're falling back to explicitly defining a new function, rather than creating it by combining higher-order functions. Which kinda defeats the point.
- shawndumas 16y agoAll I would have to do is abstract the outer function out and call it curry (partial[1], really). var add = function (m, n) { return m + n; }, partial = function (mth, fn) { return function (l) { return _(l)[mth](fn, 0); }; }, sum = partial('reduce', add); sum([1,2,3,4,5,6,7,8,9]); // => 45 ----- [1]: http://lambda-the-ultimate.org/node/2266 http://lambda-the-ultimate.org/node/2266