Lo-Dash Essentials
eBook - ePub

Lo-Dash Essentials

Adam Boduch

Share book
  1. 232 pages
  2. English
  3. ePUB (mobile friendly)
  4. Available on iOS & Android
eBook - ePub

Lo-Dash Essentials

Adam Boduch

Book details
Book preview
Table of contents
Citations

Frequently asked questions

How do I cancel my subscription?
Simply head over to the account section in settings and click on “Cancel Subscription” - it’s as simple as that. After you cancel, your membership will stay active for the remainder of the time you’ve paid for. Learn more here.
Can/how do I download books?
At the moment all of our mobile-responsive ePub books are available to download via the app. Most of our PDFs are also available to download and we're working on making the final remaining ones downloadable now. Learn more here.
What is the difference between the pricing plans?
Both plans give you full access to the library and all of Perlego’s features. The only differences are the price and subscription period: With the annual plan you’ll save around 30% compared to 12 months on the monthly plan.
What is Perlego?
We are an online textbook subscription service, where you can get access to an entire online library for less than the price of a single book per month. With over 1 million books across 1000+ topics, we’ve got you covered! Learn more here.
Do you support text-to-speech?
Look out for the read-aloud symbol on your next book to see if you can listen to it. The read-aloud tool reads text aloud for you, highlighting the text as it is being read. You can pause it, speed it up and slow it down. Learn more here.
Is Lo-Dash Essentials an online PDF/ePUB?
Yes, you can access Lo-Dash Essentials by Adam Boduch in PDF and/or ePUB format, as well as other popular books in Computer Science & Programming in JavaScript. We have over one million books available in our catalogue for you to explore.

Information

Lo-Dash Essentials


Table of Contents

Lo-Dash Essentials
Credits
About the Author
About the Reviewers
www.PacktPub.com
Support files, eBooks, discount offers, and more
Why subscribe?
Free access for Packt account holders
Preface
What this book covers
What you need for this book
Who this book is for
Conventions
Reader feedback
Customer support
Downloading the example code
Errata
Piracy
Questions
1. Working with Arrays and Collections
The difference between arrays and collections
Iterating over collections
Sorting data
Using sortBy()
Maintaining the sort order
Searching for data
Filtering collections
Finding items in collections
Slicing collections into smaller pieces
First and last collection portions
Splitting collections into chunks
Building unique arrays
Transforming collections
Grouping collection items
Counting collection items
Flattening and compacting
Validating some or all items
Unions, intersections, and differences
Summary
2. Working with Objects
Determining an object type
Type coercion
Managing function arguments
Arithmetic
Callable objects
Assigning and accessing properties
Extending objects
Defaults for new objects
Finding keys and values
Iterating over objects
Basic For Each
Including inherited properties
Keys and values
Calling methods
Getting results
Finding methods
Transforming objects
Using pairs
Picking and omitting properties
Inverting keys and values
Creating and cloning objects
Creating objects
Cloning objects
Summary
3. Working with Functions
Binding function contexts
Changing the this keyword
Binding methods
Dynamic methods
Decorating functions
Partials
Function decorators
Function constraints
Limiting call counts
Caching values
Timed execution
Delaying function calls
Deferring function calls
Throttling function calls
Debouncing function calls
Composing and currying functions
Composing functions
Currying functions
Summary
4. Transformations Using Map/Reduce
Plucking values
Mapping collections
Including and excluding properties
Performing calculations
Calling functions
Filtering and mapping
Mapping objects
Working with keys
Calling methods
Mapping key-value pairs
Reducing collections
Summing values
Filtering and reducing
Min, max, and average operations
Reducing objects
Reducing keys
Object accumulators
Binding contexts
Map/reduce patterns
Generic callback functions
Map/reduce chains
Summary
5. Assembling Chains
Creating Lo-Dash wrappers
Chained calls
Wrapping values
Explicit and implicit chaining
Building filters
Multiple filter() calls
Combining filter() with where()
Dropping and taking collection items
Rejecting items
Using initial() and rest()
Testing truth conditions
Testing if a collection contains an item
Everything or anything is true
Counting items
Using length and size()
Grouping using countBy()
Reducing collections
Transformations
Building groups, unions, and unique values
Plucking values
Creating arrays using without()
Finding the min and max values
Finding the index
Using difference() and xor()
Intermediary results
Tapping into chains
Injecting values
Keys and values
Filtered keys and values
Omitting and picking properties
Returning wrappers
Summary
6. Application Building Blocks
Generic functions
Specific functions
Generic function arguments
Using partials
Generic callbacks
Generic wrappers and chains
Generic filters
Returning chains
Composing functions
Composing generic functions
Composing callbacks
Composing chains
Method composition
Creating mixins
Creating an average() function
Creating a distance() function
Summary
7. Using Lo-Dash with Other Libraries
Modules
Organizing your code with modules
Requiring Lo-Dash
Working with Lo-Dash AMD modules
jQuery
Challenges faced by Lo-Dash
Challenges faced by jQuery
Using jQuery instances as collections
Binding functions
Working with jQuery deferred instances
Backbone
Replacing Underscore.js
Full-featured Lo-Dash and Backbone
Enhancing collections and models
Node.js
Installing the Lo-Dash package
Creating a simple command
Custom Lo-Dash builds
Summary
8. Internal Design and Performance
Design principles
Function compilation to base functions
Optimizing for the common case
Loops are simple
Callbacks and function binding
Improving performance
Changing the operation order
Sorting and indexing collections
Bound and unbound callbacks
Lazy evaluation
Caching things
Summary
Index

Lo-Dash Essentials

Copyright © 2015 Packt Publishing
All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews.
Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author, nor Packt Publishing, and its dealers and distributors will be held liable for any damages caused or alleged to be caused directly or indirectly by this book.
Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information.
First published: January 2015
Production reference: 1210115
Published by Packt Publishing Ltd.
Livery Place
35 Livery Street
Birmingham B3 2PB, UK.
ISBN 978-1-78439-833-0
www.packtpub.com

Credits

Author
Adam Boduch
Reviewers
Joe Grund
Richard Hubers
Tyler Morgan
Francois-Guillaume Ribreau
Matt Traynham
Commissioning Editor
Dipika Gaonkar
Acquisition Editor
Meeta Rajani
Content Development Editor
Pooja Nair
Technical Editor
Mrunal M. Chavan
Copy Editors
Vikrant Phadkay
Rashmi Sawant
Project Coordinator
Suzanne Coutinho
Proofreaders
Kevin McGowan
Ameesha Green
Lucy Rowland
Indexers
Priya Sane
Tejal Soni
Production Coordinator
Komal Ramchandani
Cover Work
Komal Ramchandani

About the Author

Adam Boduch is a senior frontend engineer from Toronto. He currently works on delivering innovative products at Virtustream. Adam loves tinkering with the latest JavaScript libraries and is passionate about high-performance user interfaces.
Having focused on writing about jQuery in jQuery UI Themes Beginner's Guide and jQuery UI Cookbook, both by Packt Publishing, Adam has ventured into a new territory with this title, Lo-Dash Essentials. He is an avid proponent of Backbone and the ecosystem that surrounds it.

About the Reviewers

Joe Grund is a full-stack software engineer. He has written numerous rich applications utilizing the latest technologies and methodologies. Joe enjoys writing terse JavaScript code in a functional style and building real-time systems. He works at Intel, where he uses JavaScript to solve interesting problems. He lives in Orlando and can be found on Twitter (@joegrund), GitHub (jgrund), and his blog (joegrund.com), where he muses about building complex systems out of simple functional primitives.
Richard Hubers is an all-round web developer with more than 15 years of experience. He likes writing web apps and APIs in JavaScript and .NET, and learning the newest and latest technologies. He lives and works in Amsterdam.
Tyler Morgan is a renowned Ruby developer. He loves the JavaScript landscape, especially Node.js. He is an instructor of an intensive full-stack JavaScript development course at Code Fellows, located in Seattle, Washington.
Francois-Guillaume Ribreau is a full-stack developer and Frenc...

Table of contents