Pair program with me! profile for carousel at Stack Overflow, Q&A for professional and enthusiast programmers

12/10/2012

Underscore.js

Underscore .js (_) is a small library of helper methods that deals with low level data-manipulaltion. It offers functions similar to some other languages ( Python, Ruby). Javascript lacks some of this methods, so it is really usefull to have them as a part of your toolset. Underscore is built in Jquery, so you are probably using some of these methods already ( $.extend(), $.map(),$.each()...).

Here's a quick demo how to use $.extend() method:


    var firstName = {first: "Mickey"}, // create a first object
         lastName = {last: "Mouse"}; // create a second object

    var E = $.extend(firstName, lastName); // call extend method /* with jquery, and pass objects to be merged. First one is target,and second one is a source of properties */


    dir(E); /* see new object in a chrome developer console ( or Firebug ).*/


If you want to use library outside of jquery, for a custom project you can download it here: http://underscorejs.org/

Note: you'll have to include jquery in your page, either from a local file or from CDN.

Happy Coding.

No comments:

Post a Comment