Underscore.js is one of the several tools that have emerged to improve JavaScript’s robustness and is arguably the most useful of them all. This is a JavaScript library that provides a great deal of functional programming support to the language. Its features are comparable to those of Prototye.js and Ruby but it does not extend the built-in JavaScript objects instead it chooses the functional programming design. It consists of more than 80 functions through which you can drastically transform arrays and objects to much lesser lines of code. These functions can perform several manipulations on them like mapping of arrays, creating range, inverting values of an object and many others.
Underscore.js is an absolute boon for MVC front end coders. The abstractions that come with underscore work everywhere. All its functionalities are created and exposed through a single object, the underscore character ‘_’ having a global scope.
Some interesting functionalities provided by underscore are:
• Pluck: Extract specific properties or subsets of data.
• Map: Create an array from a collection and change the elements through a function.
• All: Check all values in a collection against a particular criteria
• Uniq: Remove duplicate elements
• Range: Create a list of numbers
• Intersection: Returns common elements from two arrays
• Keys and values: For when you need either only keys or only values
• Default: Create objects with sensible defaults
Clearly, Underscore is useful and has been used in some significant websites like LinkedIn, Huffington Post and Reddit. If you want you learn more about Underscore.js, following are some useful sources that can guide you:
1. Lynda.com
Lynda.com has an amazing library of online video based courses. It provides a clear and in-depth learning for the members. The video tutorials are taught by industry experts and they provide a training for Underscore.js from beginner to advanced level. It consists of 22 video tutorials. The members are given unlimited access to every course. It is totally worth your time.
2. Getting Cozy With Underscore.js
This website is a good place to start for beginners. It give a good insight into what Underscore.js is all about and what are its capabilities. They illustrate the difference underscore can make by showing code snippets of some simple and concise examples. The language is fun and keeps you engaged throughout the tutorial. It is a good source for getting fundamental knowledge about the framework.
3. Underscore’s website
This is underscore’s official website for getting a deeper knowledge on Underscore.js. It explains the different functional programming helpers that the library offers with download links to each version of the library. It shows the functionalities of different functions on collections, objects, arrays, functions and utilities.
4. Learning Underscore.js
This book follows an example driven approach to teach essential JavaScript concepts and some good practices to build sustainable applications. This book is for developers who have a fundamental knowledge of JavaScript and want to familiarize themselves with the modern JavaScript library Underscore.js. It makes references and calls to the Underscore.js functions using them in a modern JavaScript development workflow. You can develop code targeting client, server or database concepts. You can extend underscore’s functionality with other libraries that are closely related. It also prepares you for the upcoming standard ECMAScript 6.
Underscore.js can be used for building complex and sustainable JavaScript applications as well as for building other JavaScript libraries. Even though it embraces functional programming principles, it can still be used with object-oriented, imperative functional or other programming styles. It allows you to follow a lightweight and efficient approach for building web apps. It can effectively be used on browser side or on server side. It is apparent that underscore has a great scope and developers must learn about these functionalities and put them to use.
If you know of some other good sources to learn Underscore.js, please leave a comment.