nextwebgen.com

The Next Generation Web Now

Would you like a _ with that $? New library gives JS what it should have

Filed under: Uncategorized — Dion Almaer at 11:50 pm on Wednesday, October 28, 2009

Jeremy Ashkenas and the DocumentCloud team have just released Underscore.js a small library that provides all the functional programming helpers that you expect from Prototype.js or Ruby, but without extending any core JavaScript objects.

Jeremy told us:

This makes it a natural fit alongside jQuery, without having to worry about the conflicts and redundant functionality that using Prototype and jQuery together would entail. For browsers that support the new Javascript 1.6 array functions, it delegates to the native implementations, so your “_.map()” can run at full speed, where available. It’s a tiny download, 4k when gzipped. Here’s the project page, with full documentation, live tests and benchmarks.

Some of the utilities:

Collections
each, map,
reduce, detect, select, reject, all,
any, include, invoke, pluck, max,
min, sortBy, sortedIndex, toArray,
size

Arrays

first, last,
compact, flatten, without, uniq,
intersect, zip, indexOf
,
lastIndexOf

Functions

bind, bindAll, delay,
defer, wrap
, compose

Objects

keys, values,
extend, clone, isEqual, isElement,
isArray, isFunction, isUndefined

Utility

noConflict,
uniqueId, template

There has already been nice community patches and suggestions from the community, and Kris Kowal helped make it CommonJS-compliant.

Obviously, other libraries have covered a lot of these before, but it is nice to see a small core covering.

Share and Enjoy:These icons link to social bookmarking sites where readers can share and discover new web pages.
  • blogmarks
  • del.icio.us
  • De.lirio.us
  • digg
  • NewsVine
  • YahooMyWeb

No Comments »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a comment

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>