Introduction to Underscore.js     David Jacobs     @MetaThis
What Is Underscore?• Utility library• Provides support for functional programming
General PurposeClient-side and Server-side• It has nothing to do with DOM manipulation  (unlike jQuery)• No functionality ...
Node.jsMost depended on module in NPM http://search.npmjs.org
Over 70 FunctionsCollections     Arrays           Functions    Objects                 Utility- each          - first     ...
JavaScript Functions• Functions are objects• Functions are values  – Can be assigned to a variable  – Can be passed to ano...
Functional Programming• Functional programming is using functions as  a mapping from one value to another value• Thinking ...
Map“Transform this array into a new array, using this transformation”
Reduce“Accumulate a single value from an array of values”
Filter“Give me a subset of my array that meets my conditions”
Memoize“Cache the result”
Metaprogrammingwrap _.wrap(function, wrapper)• Wraps the first function inside of the wrapper function, passing it as the ...
Functional Helperscompose _.compose(*functions)• Returns the composition of a list of functions, where each function  cons...
Flow Helpersafter _.after(count, function)• Creates a version of the function that will only be run after first being   ca...
More InfoWeb Sitehttp://documentcloud.github.com/underscoreGithubhttps://github.com/documentcloud/underscore/Annotated Sou...
Upcoming SlideShare
Loading in...5
×

Introduction to Underscore.js

2,593

Published on

Published in: Technology, Education
0 Comments
3 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
2,593
On Slideshare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
46
Comments
0
Likes
3
Embeds 0
No embeds

No notes for slide

Introduction to Underscore.js

  1. 1. Introduction to Underscore.js David Jacobs @MetaThis
  2. 2. What Is Underscore?• Utility library• Provides support for functional programming
  3. 3. General PurposeClient-side and Server-side• It has nothing to do with DOM manipulation (unlike jQuery)• No functionality specific to web browsers
  4. 4. Node.jsMost depended on module in NPM http://search.npmjs.org
  5. 5. Over 70 FunctionsCollections Arrays Functions Objects Utility- each - first - bind - keys - noConflict- map - initial - bindAll - values - identity- reduce - last - memoize - functions - times- reduceRight- find - rest - delay - extend - mixin- filter - compact - defer - defaults - uniqueId- reject - flatten - throttle - clone - escape- all - without - debounce - tap - template- any - union - once - has- include- invoke - intersection - after - isEqual Chaining- pluck - difference - wrap - isEmpty - chain- max - uniq - compose - isElement - value- min - zip - isArray- sortBy - indexOf - isArguments- groupBy- sortedIndex - lastIndexOf - isFunction- shuffle - range - isString- toArray - is…(more like this)- size
  6. 6. JavaScript Functions• Functions are objects• Functions are values – Can be assigned to a variable – Can be passed to another function as an argument – Can be returned by a function
  7. 7. Functional Programming• Functional programming is using functions as a mapping from one value to another value• Thinking and programming in a functional style means using higher-order functions – Composition – Chaining
  8. 8. Map“Transform this array into a new array, using this transformation”
  9. 9. Reduce“Accumulate a single value from an array of values”
  10. 10. Filter“Give me a subset of my array that meets my conditions”
  11. 11. Memoize“Cache the result”
  12. 12. Metaprogrammingwrap _.wrap(function, wrapper)• Wraps the first function inside of the wrapper function, passing it as the first argument. This allows the wrapper to execute code before and after the function runs, adjust the arguments, and execute it conditionally.tap _.tap(object, interceptor)• Invokes interceptor with the object, and then returns object.
  13. 13. Functional Helperscompose _.compose(*functions)• Returns the composition of a list of functions, where each function consumes the return value of the function that follows. In math terms, composing the functions f(), g(), and h() produces f(g(h())).
  14. 14. Flow Helpersafter _.after(count, function)• Creates a version of the function that will only be run after first being called count times. Useful for grouping asynchronous responses, where you want to be sure that all the async calls have finished, before proceeding.
  15. 15. More InfoWeb Sitehttp://documentcloud.github.com/underscoreGithubhttps://github.com/documentcloud/underscore/Annotated Source Code (useful!)http://documentcloud.github.com/underscore/docs/underscore.html
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×