The purpose of Alex Pop's Learning Underscore.js (Packt Publishing, October 2015) is to "explore the Underscore.js library using a test-driven development approach." There are seven chapters in this book on Underscore.js covering just under 200 substantive pages.
Chapter 1: Getting Started with Underscore.js
_) are introduced in the context of these first two examples.
Other examples in Chapter 1 illustrate Underscore's support for functions countBy, pairs, each, map, and reduce. Because these last few Underscore functions are functional in nature, it's a natural fit or this section of the first chapter to provide brief background on "functional programming style."
Chapter 2: Using Underscore.js with Collections
The second chapter of Learning Underscore.js revisits the "key Underscore functions"
Chapter 2 delves into searching with Underscore and introduces Underscore functions
contains in addition to revisiting
find. Similarly, the second chapter's dive into sorting looks at Underscore functions
The first chapter had introduced an example of an aggregate function (
reduce) and of a transformation function (
map). The second chapter defines the difference between these two types of functions, delves more deeply into how to apply both of these types of functions, and introduces new Underscore functions of each type. The newly introduced aggregation functions are
min and the newly introduced transformation functions are
Chapter 3: Using Underscore.js with Arrays, Objects, and Functions
Chapter 3 of Learning Underscore.js begins by looking at some array-specific functions provided by Underscore: first, rest,
initial, union, intersection, difference, and zip. It also looks more briefly at several other "array-related functions."
The third chapter's section "Objects" opens with the sentence, "Underscore has a series of dedicated functions targeting objects, which extends the features provided for collections." Functions covered (code listings and explanations) in this section include keys, allKeys, values, invert, pairs, contains, pick, omit, extend, clone, has, property, propertyOf, matcher, isEqual, and isMatch. This section also looks at "assertion functions" for "object validation," "determining object types," for String objects, and for Number objects.
Chapter 3's section "Functions" opens with the sentence, "Underscore has a series of functions that specifically target objects of the type
Function: it has functions that target other functions." The section discusses bind, bindAll, partial, memoize, wrap, negate, compose, delay, throttle and debounce, once, after, and before. The third chapter ends with a list o miscellaneous utility functions each with very brief descriptions.
Chapter 4: Programming Paradigms with Underscore.js
Chapter 5: Using Underscore.js in the Browser, on the Server, and with the Database
Chapter 6: Related Underscore.js Libraries and ECMAScript Standards
Underscore-contrib is introduced in this sixth chapter. The chapter explains the relationship of Underscore to Underscore-contrib and provides "an overview of Underscore-contrib functionality." It covers select functions from the sub-libraries provided by Underscore-contrib, discusses installing Underscore-contrib, and provides a couple of examples of applying Underscore-contrib.
It surprised me a bit that a book about Underscore and with "Underscore" in the title mentioned ways in which lodash might be considered superior to Underscore. There is even a section in Chapter 6 on "migrating a project from Underscore to lodash", a reference to a Wiki page on migrating from Underscore to lodash, and a reference to another Packt Publishing title Lo-Dash Essentials.
The section "ECMAScript 2015 (ES6)" describes advantages offered by ES6 and describes features of ES6. This section references the ECMAScript 6 Compatibility Table and explains how transpilers can be used to "convert code from ... upcoming ECMAScript specifications ... into code that is compatible with older specifications." Babel is introduced as a transpiler for converting ES6 code to ES5 code and examples of using Babel from a web browser, from the command-line, and in conjunction with Node.js are provided. Several examples are provided of using Babel to use ES6 functionality.
Chapter 7: Underscore.js Build Automation and Code Reusability
The final chapter of Learning Underscore.js begins by looking at installing Gulp and using Gulp for deployments. The chapter also includes a section "Reusing code based on Underscore between client and server" that covers use of CommonJS, Browserify, Jasmine, and Gulp to enable using code on client and server. The final section of the chapter and of the book illustrates using babelify to add "ECMAScript 2015 (ES6) support to Browserify."
- I liked that Learning Underscore.js liberally referenced online materials for more details on many of the topics it introduced. Some of these articles and resources are excellent and I was glad to have them pointed out.
- Learning Underscore.js includes numerous code listings. Even in the PDF copy of the book that Packt Publishing provided for my review, the code listings are black font on white background with no color syntax and no line numbers. However, each chapter references where the code can be downloaded to be used in the reader's favorite IDE or editor. These references include Cloud9 links.