Book Image

Learning Underscore.js

By : Alexandru Vasile Pop
Book Image

Learning Underscore.js

By: Alexandru Vasile Pop

Overview of this book

Table of Contents (14 chapters)
Learning Underscore.js
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Functions


Underscore has a series of functions that specifically target objects of the type Function: it has functions that target other functions. This subsection touches on some of the functional programming concepts that will be explored in detail in Chapter 4, Programming Paradigms with Underscore.js.

Functional composition with bind, bindAll, and partial

The first function is _.bind(function, object, *arguments) that returns a new function wrapper for the original function parameter. The wrapper function has the this value set to the object parameter and its arguments will be prefilled in order with the values from the *arguments parameters. The returned function is also known as bound function and is an example of functional composition in action. Through functional composition, we can create new functions based on existing functions in scenarios where we cannot change the original function implementation (we don't own the code) or it is more convenient to do so. It is a core technique...