Introduction to Underscore.js

3,599 views

Published on

Underscore is a utility-belt library for JavaScript that provides a lot of the functional programming support that you would expect in Prototype.js (or Ruby), but without extending any of the built-in JavaScript objects. It's the tie to go along with jQuery's tux.

Published in: Technology

Introduction to Underscore.js

  1. 1. André Faria@andrefaria Underscore.js http://documentcloud.github.com/underscore/
  2. 2. Underscore is a utility-belt library for JavaScript that provides a lot of the functionalprogramming support that you would expect in Prototype.js (or Ruby), but without extending any of the built-in JavaScript objects. Its the tie to go along with jQuerys tux.
  3. 3. Underscore provides 60-odd functions that support both the usual functional suspects: map, select, invoke — as well as morespecialized helpers: function binding, javascript templating, deep equality testing, and so on.
  4. 4. It delegates to built-in functions, if present, so modern browsers will use the nativeimplementations of forEach, map, reduce, filter, every, some andindexOf.
  5. 5. 2 Versions
  6. 6. Object Orientedand Fuction Styles your preference
  7. 7. Using the object-oriented style allows you to chain together methods. Calling chain on a wrapped object will cause all future method calls to return wrappedobjects as well. When youve finished the computation, use value to retrieve the final value.
  8. 8. Collection Functions (Arrays or Objects)
  9. 9. Array FunctionsAll array functions will also work on the arguments object.
  10. 10. Functions
  11. 11. Objects
  12. 12. Utility
  13. 13. Chaining
  14. 14. There’s more
  15. 15. Thanks very much and now go try it out @andrefaria

×