Sign In Start Free Trial
Account

Add to playlist

Create a Playlist

Modal Close icon
You need to login to use this feature.
  • Book Overview & Buying Learning UnderscoreJS
  • Table Of Contents Toc
Learning UnderscoreJS

Learning UnderscoreJS

By : Pop
4.6 (5)
close
close
Learning UnderscoreJS

Learning UnderscoreJS

4.6 (5)
By: Pop

Overview of this book

Underscore.js is one of the most popular modern JavaScript libraries used for functional programming. It can be used as a base for building complex JavaScript applications in a sustainable manner and for building other JavaScript libraries. It embraces functional programming principles but is not opinionated and can be used with imperative, object-oriented, functional, or other programming styles. This book explores how to use Underscore.js to power your code and understand modern JavaScript development concepts while applying a lightweight and efficient workflow to build applications. The book starts with an incremental Underscore.js introduction by exploring key JavaScript concepts. You will then explore the basic features of Underscore.js in action and establish a lightweight development workflow that allows the provided examples to be guided by tests. The book then covers the functionality of Underscore.js with in-depth examples and explanations for understanding and applying the Underscore.js API. You'll also learn how to use Underscore.js as a base for your own modules and libraries within an object-oriented or functional programming style, and will be able to explore Underscore.js use cases in different environments. Eventually, you'll learn about libraries that are closely related with Underscore.js, how to share code between client and server, and how to prepare for the upcoming JavaScript standard ECMAScript 6.
Table of Contents (9 chapters)
close
close
8
Index

Why Underscore

In the last couple of years, the JavaScript programming language has extended its reach dramatically. While initially it was a browser-based scripting language, it is now used in server-side applications via platforms such as Node.js or in mobile and desktop applications via frameworks such as PhoneGap and Node-Webkit. Database engines such as MongoDB and PostgreSQL also use JavaScript, and this makes it possible to write an application using the same programming language throughout all its layers and components. Another significant change that raised the importance of JavaScript was the emergence of libraries and frameworks that targeted the browser as an application platform. Libraries such as jQuery enabled cross-browser HTML element manipulation, among other features, and frameworks such as Backbone.js facilitated building single page applications.

Note

A single page application (also known as SPA) has the user interface rendering and navigation happening in the browser rather than on the server.

The library presented in this book is called Underscore and provides an extensive set of functions that simplify and enhance handling of JavaScript objects, arrays, and functions. It accomplishes this by providing missing functional programming features to JavaScript. By using Underscore JavaScript gains a better level of usability that makes coding easier and more expressive on a similar level to other general purpose programming languages.

Version 1.0 of Underscore was launched in 2010 around the time when single page applications started to gain more ground. Underscore is used in Backbone.js as both have the same author, and after its launch it has become one of the most popular JavaScript libraries. At the time of writing this book, Underscore has reached version 1.8.3, which will be the version used throughout all examples.

Underscore is representative of a good JavaScript utility library as it provides solutions for a specific problem domain rather than being a catchall utility. It also has very good online documentation (including annotated source code) that is available at http://underscorejs.org/, which is another distinctive attribute of a good software library. This book will explore Underscore by presenting a series of more involved examples than the ones provided with its library documentation.

To understand why Underscore is so popular, we need to discuss the ECMAScript 5 (ES5) specification and what it meant for JavaScript as a programming language. Technically, JavaScript is a specific implementation of an open language specification called ECMAScript. The current version of this specification was finalized at the end of 2009 and is known as ECMAScript 5 (or ECMAScript 5.1 to be very specific). This version added functionality for the built-in JavaScript objects, Array and Object, included new functional features, and improved the meta-programming story among other changes. Soon after its release, it started to be adopted by all major browsers, including Internet Explorer from version 9. There was still a large number of users relying on browsers such as Internet Explorer 6, 7, and 8 that were unlikely to upgrade too quickly to Internet Explorer 9 compared to users of browsers such as Mozilla Firefox and Google Chrome that had faster release and upgrade cycles. As Underscore provided support for some of the functionality introduced by ECMAScript 5, this made it a useful library for web applications targeting older browsers such as Internet Explorer 8, and for developers that wanted to write code that was based on ES5 without worrying about browser support. Although ES5 support is important, this is just a small feature of Underscore compared to the rest of its features.

All of this book's examples assume that they are executed against a JavaScript version that is ES5 compliant. All the examples can be executed on Windows, Mac OS X, and Linux, and we will mainly target Google Chrome and Mozilla Firefox that are the most popular cross platform browsers (although you should not have issues running the examples in other browsers).

Note

Technically, Underscore is not directly compatible with ES5 starting from version 1.7.0, and we will discuss more about standards compliance in Chapter 6, Related Underscore.js Libraries and ECMAScript Standards.

ES 5 support for older browsers should be provided through a library targeting this feature exclusively such as es5-shim. This library is available at https://github.com/es-shims/es5-shim, where you can find more details about its features.

CONTINUE READING
83
Tech Concepts
36
Programming languages
73
Tech Tools
Icon Unlimited access to the largest independent learning library in tech of over 8,000 expert-authored tech books and videos.
Icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Icon 50+ new titles added per month and exclusive early access to books as they are being written.
Learning UnderscoreJS
notes
bookmark Notes and Bookmarks search Search in title playlist Add to playlist font-size Font size

Change the font size

margin-width Margin width

Change margin width

day-mode Day/Sepia/Night Modes

Change background colour

Close icon Search
Country selected

Close icon Your notes and bookmarks

Confirmation

Modal Close icon
claim successful

Buy this book with your credits?

Modal Close icon
Are you sure you want to buy this book with one of your credits?
Close
YES, BUY

Submit Your Feedback

Modal Close icon
Modal Close icon
Modal Close icon