What Is Underscore?
Underscore.js is a JavaScript library supporting functional programming.
Getting Underscore
The Underscore website has the latest version of the library.
Using Underscore
_.times(4, function() {console.log("Major")});
// (console) Major
// (console) Major
// (console) Major
// (console) Major
var underscore = _.noConflict();
underscore.times(4, function() {console.log("Major")});
// (console) Major
// (console) Major
// (console) Major
// (console) Major
The Source Code for Functional JavaScript
Lemonad library and the official underscore-contrib library
Running the Code in This Book
The source code for Functional JavaScript is available on GitHub.
Notational Conventions
- Avoid assigning variables more than once.
- Do not use
eval
. - Do not modify core objects like Array and Function.
- Favor functions over methods.
- If a function is defined at the start of a project, then it should work in subsequent stages as well.
- Functions of zero parameters are used to denote that the arguments don't matter.
- In some examples, ... is used to denote that the surrounding code segments are being ignored.
- Text like inst#method denotes a reference to an instance method.
- I tend to restrict if/else statements to a single line per branch, so I prefer to avoid using curly brackets to wrap the blocks. This saves precious vertical space.
- I like to use semicolons.
Whom Functional JavaScript Is Written For
Anyone looking to learn more about functional programming.
A Roadmap for Functional JavaScript
Chapter 1, Introducing Functional JavaScript
Chapter 2, First-Class Functions and Applicative Programming
Chapter 3, Variable Scope and Closures
Chapter 4, Higher-Order Functions
Chapter 5, Function-Building Functions
Chapter 6, Recursion
Chapter 7, Purity, Immutability, and Policies for Change
Chapter 8, Flow-Based Programming
Chapter 9, Programming Without Class
Conventions Used in This Book
Using Code Examples
......