Underscore.js Fundamentals

Learn to take control of JavaScript collections, arrays, functions and objects all while improving the performance of your code and making your JavaScript more readable and expressive.
Course info
Rating
(294)
Level
Intermediate
Updated
May 8, 2013
Duration
2h 55m
Table of contents
Introduction
Collections
Arrays
Functions
Chaining and Objects
Utilities
Underscore by Example
Description
Course info
Rating
(294)
Level
Intermediate
Updated
May 8, 2013
Duration
2h 55m
Description

Learn Underscore.js by focusing on each of the Underscore functions to learn to manipulate and control JavaScript collections, arrays, objects and functions. See how Underscore can significantly improve the performance of your code and how to the functional nature of the library can help make your code more expressive and easier to read. The last module of the course demonstrates how to use Underscore in an integration exercise to create aggregations, data manipulations, integrate with a ViewModel and extend the library to add your own functionality.

About the author
About the author

Craig Shoemaker is a developer, instructor, writer, podcaster, and technical evangelist of all things awesome.

More from the author
HTML5 Fundamentals
Beginner
3h 47m
Mar 3, 2017
jQuery: Getting Started
Beginner
1h 40m
Jun 3, 2015
More courses by Craig Shoemaker
Section Introduction Transcripts
Section Introduction Transcripts

Introduction
Hello and welcome to Underscore. js Fundamentals on Pluralsight. This is Craig Shoemaker and during this course, I'll take you step-by-step through the Underscore library. So that when our time together is complete, you'll be ready to use Underscore in everyday development scenarios. First, I'll take you on a sightseeing tour through the vast Underscore API, where I'll show you dozens of code samples where you can see Underscore in action. Along the way, we'll spend some time uncovering some of the concepts and algorithms supported by Underscore and finish up with some integration exercises where you'll see how Underscore is used in some real-life situations. Well, thanks again for joining me. Let's go ahead and get started.

Arrays
Underscore functions crafted to work with Arrays give you an opportunity to extract items, find overlapping data, find specialized indices, and much more. Alright, let's begin with the first function. The first function returns the first element in an array. And if you pass in an Explicit Amount as an argument, it'll take the first number of items based off of the number you pass in. So, take(authors, 2) returns the first two items within the array. Just like first, the initial function returns everything except for the last item in the array. Now, if you want that change that up a little bit and pass in a value for the last argument, it will take everything except for the last number amount that you pass in. Following the same pattern as first and initial, last will return to you the last item in an array. Now, if you pass in a value as the last argument to the function, it'll return to you the last end number of items in the array. Finally, the last function in this kind of "group" of functions is rest and rest will give you everything except the first element in the array. Of course, unless you pass in a specific index, which indicates which index to start at in order to give you the rest of the elements in the array.

Functions
The series of Underscore Functions that are crafted to work specifically with your functions can greatly help you gain control of how your code is executed, manage where data is coming from, and help guard against some of the odd behavior found in native JavaScript. The bind and bindAll functions help you manage the JavaScript this pointer, wrap and compose give you some handy utilities for making functions work together, and all the others in-between help performance or help you gain precise control on how functions are called.

Chaining and Objects
Underscore shines in helping you manage, create, and manipulate Objects. This module delves into the series of functions built to work specifically with JavaScript Objects. Now, since everything in JavaScript is an object of some sort, you can see from the second column that there are a number of functions that help you determine one object from another. But, before we deal with the object functions, there are a few features of Underscore that I've left until now to discuss.

Utilities
In this module, I'll discuss the final set of functions found in the Utility section of Underscore. Now make sure to stick around for the last module in the course while I'll take you through an integration demo where you can see many of the functions you've become familiar with up to this point working together in a more real-world implementation. For now though, we'll discuss the series of utilities that round off the effectiveness and ability of Underscore. js.