034 Lodash

22 Feb 2013

Lodash is a utility belt JavaScript library. It is also a hard dependency for BackboneJS, as a drop-in replacement for UnderscoreJS with performance enhancement. In this episode we will create a simple project using some functions of Lodash along with its micro templating features. We will also explore the custom build functions and source maps.

Download video: mp4

Sample code: Github

Version: 1.0.1

Background on Lodash

  1. Main website
  2. Documentation
  3. Github
  4. Uses: Drop-in replacement for Underscorejs, a dependancy for Backbonejs

Things to learn with Lodash

1. link to lodash js file

  1. link to lodash from the cdnjs or get your own copy

      <script src="//cdnjs.cloudflare.com/ajax/libs/lodash.js/1.0.0-rc.3/lodash.min.js"></script>
    
  2. check in your console on the lodash functions available and its version:

    _.functions(_)
    _.VERSION
    

2. Try out different lodash functions

  1. For Arrays: _.compact, _.object
  2. For Collections: _.where, _.min, _.max
  3. For Objects: _.functions
  4. For Utilities: _.template to create a template for markup and _.templateSettings to set the syntax

3. Custom Builds

  1. install npm package sudo npm install -g lodash
  2. check the version lodash --version
  3. custom build it

    lodash include="compact, each, object, where, min, max, functions, templateSettings, template"
    

More Resources on Lodash

  1. Underscorejs
  2. Mout
  3. Say Hello to Lodash
  4. Getting cosy with Underscore js
  5. Introducing lodash
  6. Lodash for a better utility belt

Build Link of this Episode

Javascript Playground