Monday, December 7th, 2009

Underscore.js gets some updates with 0.5

Category: JavaScript, Library

<p>We posted on the underscore.js initial announcement and we liked what we saw.

Jeremy Ashkenas of underscore.js pinged us to let us know that it is chuggin’ along and the library is now up to 0.5 and has had changes such as:

  • OOP-style wrapping: _([1, 2, 3, 4, 5]).each( ... );
  • OOP wrapping allows you to chain together computations: _([1, 2, 3, 4, 5]).chain().map( ... ).flatten().reduce( ... ).value();
  • Added speed comparisons with jQuery to the test page. Because Underscore delegates to the native implementations whenever available, its “each” function is over 5 times faster than jQuery.each in Safari, and over 3.5 times faster in Firefox. Your mileage may vary, so you can use the test page to check it in your browser of choice.
  • Added reduceRight / foldr, to go along with reduce / foldl.
  • Added first / head, and rest / tail for car and cdr enthusiasts. It turns out that they’re immensely useful on JS arguments objects.
  • Added a “range” function, identical to Python’s range(), for easy array initialization.
  • A slew of other minor improvements, to get Underscore working out-of-the-box on Rhino, to use the native StopIteration object to break out of loops where available, and so on.

The latest Underscore.js 0.5.0 includes a couple of API cleanups, a couple of speedups, and a more comprehensive isEqual() function, with Date, NaN, and RegExp support.

Marcus Irven has ported the commonly-applicable Underscore functions to Lua, and released an Underscore.lua library this weekend.

Related Content:

3 Comments »

Comments feed TrackBack URI

Wicked update. I’ve always loved this library and was going to implement chaining for it myself, now I needn’t bother. Choice one!

Comment by Patmania — December 7, 2009

Sweet.

Comment by JohnDeHope3 — December 8, 2009

thanks

Comment by Aphrodisiac — January 15, 2010

Leave a comment

You must be logged in to post a comment.