Book Image

Lo-Dash Essentials

By : Adam Boduch
Book Image

Lo-Dash Essentials

By: Adam Boduch

Overview of this book

Table of Contents (15 chapters)
Lo-Dash Essentials
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Preface

At times, JavaScript can be a frustrating programming language to work with. Just when you think you have it entirely figured out, performance or cross-browser issues reveal themselves in the worst possible way. Lo-Dash is just one of many libraries that aim to help JavaScript programmers write code that's elegant, efficient, and portable. Underscore.js introduced a better way to perform functional programming with JavaScript. Lo-Dash is a continuation of this effort, and throughout this book, we'll see what sets Lo-Dash apart from other libraries out there, including Underscore.

At its heart, JavaScript is a functional language, but not necessarily a pure functional language—you can modify variables and introduce side effects. However, functions are first-class citizens and you can do a lot with them. Lo-Dash embraces this idea and gives programmers all the tools they need to write functional code that's readable and maintainable. All the cool things you can do with higher-order functions in other languages are possible with Lo-Dash as well.

It's not just the low-level utilities and performance gains that Lo-Dash delivers, though these are always welcome; it's also the enhanced programming model and the ideas that Lo-Dash borrows from other languages such as functional and applicative programming. These are imparted to JavaScript applications as a coherent API. Underscore got the ball rolling, and Lo-Dash further enhances these ideas, albeit using different design and implementation strategies.

What this book covers

Chapter 1, Working with Arrays and Collections, explains that collections are similar to arrays but are more general than arrays. This chapter looks at the differences between these two constructs and the available Lo-Dash functions that operate on them.

Chapter 2, Working with Objects, teaches you how Lo-Dash treats objects as collections. This chapter looks at the available functions that work with objects.

Chapter 3, Working with Functions, focuses on the functional tools provided by Lo-Dash.

Chapter 4, Transformations Using Map/Reduce, explains that the map/reduce programming model is used often in the Lo-Dash code. This chapter offers many examples that utilize the Lo-Dash map/reduce tools in their various forms.

Chapter 5, Assembling Chains, explains how Lo-Dash can chain together functions that operate on a value. This chapter explores what chains are and how they work.

Chapter 6, Application Building Blocks, looks at the high-level application components that help organize the Lo-Dash code.

Chapter 7, Using Lo-Dash with Other Libraries, explains that Lo-Dash doesn't do everything. This chapter uses examples to illustrate where other libraries can help Lo-Dash and vice versa.

Chapter 8, Internal Design and Performance, looks at some of the internal design decisions of Lo-Dash and provides some advice on how to improve the performance of your Lo-Dash code.

What you need for this book

The only software required for running the examples in this book is a modern web browser. All JavaScript libraries are packaged with the code samples. The only exception is Chapter 7, Using Lo-Dash with Other Libraries, which involves working with Node.js (http://nodejs.org/) and some corresponding npm packages.

Who this book is for

This book is for the intermediate JavaScript programmer who is either new to Lo-Dash or has been using it for a while. Whether you've never written a line of Lo-Dash or you've got Lo-Dash code running in production, this book has something for you. Ideally, you've written some intermediate/advanced JavaScript code and utilized libraries such as jQuery or Backbone.

Conventions

In this book, you will find a number of styles of text that distinguish between different kinds of information. Here are some examples of these styles, and explanations of their meanings.

Code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles are shown as follows: "The union() function concatenates collections, with duplicate values removed."

A block of code is set as follows:

var collection = [ 
    { name: 'Jonathan' },
    { first: 'Janet' },
    { name: 'Kevin' },
    { name: 'Ruby' }
];

if (!_.every(collection, 'name')) {
    return 'Missing name property';
}
// → "Missing name property"

Any command-line input or output is written as follows:

npm install -g grunt-cli grunt-contrib-connect

Note

Warnings or important notes appear in a box like this.

Reader feedback

Feedback from our readers is always welcome. Let us know what you think about this book—what you liked or may have disliked. Reader feedback is important for us to develop titles that you really get the most out of.

To send us general feedback, simply send an e-mail to , and mention the book title via the subject of your message.

If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide on www.packtpub.com/authors.

Customer support

Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.

Downloading the example code

You can download the example code files from your account at http://www.packtpub.com for all the Packt Publishing books you have purchased. If you purchased this book elsewhere, you can visit http://www.packtpub.com/support and register to have the files e-mailed directly to you.

Errata

Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you find a mistake in one of our books—maybe a mistake in the text or the code—we would be grateful if you could report this to us. By doing so, you can save other readers from frustration and help us improve subsequent versions of this book. If you find any errata, please report them by visiting http://www.packtpub.com/submit-errata, selecting your book, clicking on the Errata Submission Form link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata will be uploaded to our website or added to any list of existing errata under the Errata section of that title.

To view the previously submitted errata, go to https://www.packtpub.com/books/content/support and enter the name of the book in the search field. The required information will appear under the Errata section.

Piracy

Piracy of copyrighted material on the Internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works in any form on the Internet, please provide us with the location address or website name immediately so that we can pursue a remedy.

Please contact us at with a link to the suspected pirated material.

We appreciate your help in protecting our authors and our ability to bring you valuable content.

Questions

If you have a problem with any aspect of this book, you can contact us at , and we will do our best to address the problem.