Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Backbone.js Patterns and Best Practices

You're reading from   Backbone.js Patterns and Best Practices Improve your Backbone.js skills with this step-by-step guide to patterns and best practice. It will help you reduce boilerplate in your code and provide plenty of open source plugin solutions to common problems along the way.

Arrow left icon
Product type Paperback
Published in Jan 2014
Publisher Packt
ISBN-13 9781783283576
Length 174 pages
Edition Edition
Languages
Arrow right icon
Author (1):
Arrow left icon
Swarnendu De Swarnendu De
Author Profile Icon Swarnendu De
Swarnendu De
Arrow right icon
View More author details
Toc

Table of Contents (19) Chapters Close

Backbone.js Patterns and Best Practices
Credits
About the Author
Acknowledgments
About the Reviewers
www.PacktPub.com
Preface
1. Reducing Boilerplate with Plugin Development FREE CHAPTER 2. Working with Views 3. Working with Models 4. Working with Collections 5. Routing Best Practices and Subrouting 6. Working with Events, Sync, and Storage 7. Organizing Backbone Applications – Structure, Optimize, and Deploy 8. Unit Test, Stub, Spy, and Mock Your App Books, Tutorials, and References Precompiling Templates on the Server Side
Organizing Templates with AMD and Require.js Index

Using Underscore.js


Underscore.js (http://underscorejs.org/) is a powerful utility library that provides a lot of functional programming support for your JavaScript code. In general, JavaScript comes up with a very low number of utility methods on its own, and most of the time we need to either develop our own functions or depend on another library for these methods. Underscore comes up with a bagful of highly efficient utility methods, which makes it an excellent tool for your JavaScript projects. The functions it provides can be grouped into the following sections:

  • Collections (Array or Object)

  • Arrays

  • Functions

  • Objects

  • Utility

  • Chaining

These include functions for iterations, sorting, filtering, conversions, templating, comparisons, scope binding, and many more. The main benefits of using this small library are as follows:

  • It helps you to make the JavaScript code more intuitive and concise.

  • In addition to the convenient methods, Underscore also implements cross-browser versions of newer JavaScript functions, which are only available in modern browsers. Underscore will detect whether the browser supports the method, and will use the native implementation if it is present. This boosts the function's performance to a great extent.

  • The minified and gzipped version of the library weighs only 4.9 KB, which leaves little excuse for not taking advantages of this library.

  • The library is completely DOM-free—so you can use it for your server-side JavaScript code as well.

  • Excellent documentation similar to Backbone.js with examples is available at http://underscorejs.org/.

Backbone.js has a hard dependency on Underscore.js, and you are bound to use it if you are developing your applications with Backbone.js. However, even when you are not using Backbone, we encourage you to use Underscore.js for your JavaScript projects. It adds no overhead, integrates easily, and makes your code more robust even when you are not aware of all the underlying engineering principles employed by this library.

There is another library named Lo-dash (http://lodash.com), which provides an Underscore built to perform drop-in replacement of the Underscore.js library. It is said to have a slightly better performance than Underscore.js. You can try either of them to achieve the same result.

You have been reading a chapter from
Backbone.js Patterns and Best Practices
Published in: Jan 2014
Publisher: Packt
ISBN-13: 9781783283576
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image