Programming JavaScript Applications

Your guide to building full web-scale applications. Buy now!

With this digital Early Release edition of Programming JavaScript Applications, you get the entire book bundle in its earliest form, so you can take advantage of this content long before the book’s official release. You’ll also receive updates when significant changes are made, as well as the final ebook version.

Take your existing JavaScript skills to the next level and learn how to build complete web scale or enterprise applications that are easy to extend and maintain. By applying the design patterns outlined in this book, you’ll learn how to write flexible and resilient code that’s easier—not harder—to work with as your code base grows.

JavaScript has become one of the most widely used—and essential—programming languages for the Web, on both the client-side and server-side. In the real world, JavaScript applications are fragile, and when you change them things often break. Author Eric Elliott shows you how to add features without creating bugs or negatively impacting the rest of your code during the course of building a large JavaScript application.

Learn about:

  • AMD
  • Asynchronous Operations, Callbacks, Promises and Deferreds
  • Code Quality
  • Event-driven, Modular Client Side Application Architecture
  • Feature Toggles
  • Function Polymorphism
  • Function Scope, Hoisting and Closures
  • Functional Programming and Stateless Functions
  • Immediately Invoked Function Expressions
  • Internationalization
  • Interfaces
  • JavaScript Style
  • Lambdas
  • Logging and Cross Cutting Concerns
  • Method Chaining and Fluent APIs
  • Method Context
  • Named Parameters
  • Node Modules
  • Object Factories
  • Partial Application and Currying
  • Plugins
  • Principles of Modularity
  • Prototypal Inheritance, Prototype Cloning and Stamps
  • RESTful APIs with Node.js
  • Separatian of Concerns (MVC, etc.)
  • The Module Pattern
  • Unit Testing

An interview with Eric Elliott, Author of “Programming JavaScript Applications”

by Adam Flaherty (O’Reilly)

1. Why is your book timely – what makes it important right now?

JavaScript is really hot right now. It’s the most-used and most in-demand programming language in the world, and the upward trend that got us here is still growing. The realm of possibilities with JavaScript is expanding right on with it. These days, the browser is the platform for almost every type of app, from productivity tools to fully immersive 3D video games. It’s also expanded into the back end, where it powers production servers for the biggest (and smallest) companies in the business. Learning JavaScript and Node will put you on the most wanted list of thousands of technical recruiters.

2. What information do you hope that readers of your book will walk away with?

Most JavaScript professionals had limited experience working with JavaScript in full scale applications when I started working on the book. There were few other books that talked about modern JavaScript techniques, or how to use JavaScript to build large applications. I want the readers to walk away with a better understanding of modern application architecture and programming techniques, from unit testing to front end separation of concerns (like MVC), to writing web services in Node. It’s more of an overview of each area than a deep dive into any particular one, but it should give an experienced programmer enough examples and insights to get started, and to have some idea of where to go next.

3. What’s the most exciting/important thing happening in your space?

It’s so hard to say there’s a most exciting thing happening in the JavaScript world. So many things are taking off at the same time. Node is exploding. It’s being used for everything from web servers to robotics, including artificial vision and audio processing.

WebGL games and demos are showing technology that would have been impressive on native desktops five years ago. It might be another five years before web games can compete with the technical capabilities of today’s desktop and platform games, but it’s clear that’s the direction we’re headed in.

That’s really exciting for more than just the game community. It will also impact consumer expectations of what’s possible with website user interfaces. I think we’ll see the shift first in entertainment properties and ad agency content, but the web experience is definitely going to get more immersive in the very near future. It’s already starting to happen.

Of course, all of that will benefit from the dramatic changes coming to the JavaScript language itself. ES6 is well on its way to adding some very cool features to JavaScript. Destructuring assignments, generators, rest parameters, and array comprehension are all exciting and welcome additions to the language. It may be a while before we can freely use these new features in our browser code, but some of them are available for experimentation right now.

4. Please include a short list of 5 tips and tricks.

1. Write short functions. In JavaScript, you’ll have some long functions that are unavoidable (such as wrappers for module scope), but the stuff that’s actually doing all the work should be really short. Aim for les than about a dozen lines. Short functions are more flexible, more reusable, and much easier to read. Keep it simple.

2. Unit test all of your surface-area code. That means, if you export a function for somebody else to use, that function should be covered by tests. Make sure you remember to test for edge and error cases.

Unit tests are more than just an assurance that your code does what it’s supposed to do. They can also act as an implementation checklist to help you while you’re developing your code. Of course, the best part about unit tests is that code is a changing, ever evolving thing. Unit tests give you the assurance that when you go in and make changes, whether they’re bug fixes, feature additions, or refactors, you’ll know right away if anything goes wrong. Just run your test suite and make sure the tests still pass.

Unit tests teach you discipline, and provide you with a deep debugging insight into your code. It really helps to know what still works and what doesn’t when a bug creeps in, and short of littering your code with all sorts of logging statements, unit tests give you better insight into that than almost anything else you can do. I know there are lots of developers on the fence about this, or just not sure where to begin. Here’s your kick: It’s worth the effort to figure it out.

3. Don’t get attached to any particular implementation of your code. A month from now, you’re going to wish you’d done things differently. Get used to it. Once you’ve set down your code, forget about the pride in your implementation. The important questions are, “does it do the job?” and “will it be easy to change?” — emphasis on the second question.

“Code by itself almost rots and it’s gotta be rewritten. Even when nothing has changed, for some reason, it rots.” – Ken Thompson

4. Learn the native capabilities of JavaScript, and take advantage of them. In particular, functional programming techniques (lambdas / closures / partial application, the words sound more complicated than the techniques actually are), object literals, dynamic object extension, prototypes, factories, and fluent APIs for objects (lots of methods could be improved if they returned this). When used together, I call this “fluent style JavaScript”, referring to fluency in a language. I didn’t invent it (jQuery is written in mostly fluent style, for example). It’s just what people who are fluent in JavaScript do.

5. Really learn prototypes. No, I don’t mean learn how to assign things to a constructor prototype, I mean really learn how to use prototypes to full advantage. For more on why prototypes are so cool, and a simple tool that will help you use them effectively, see this post on my blog: Fluent JavaScript: Three Different Kinds of Prototypal OO.

  1. Michael - November 25, 2012

    Hi, great book there. However when are we going to see the next update of the “early release”? ;)

    • Eric Elliott - November 29, 2012

      I have submitted an update that covers building client-side applications using npm, CommonJS modules, Grunt and Browserify. It briefly mentions alternative build processes such as Yeoman + Bower + Grunt. You’ll also get a sneak peek at Chapter 6 (arguably the hardest chapter to write), still in progress. It covers client side separation of concerns, working with events, and piecing together modules around a core application sandbox. Parts of that will change before the actual release.

      • Eric Elliott - December 6, 2012

        In case you didn’t get a notification, there is an update available now that gives a little glimpse of things to come in the second half of the book. It’s developing quickly, again.

  2. Hello Eric,
    I’m interested in buying this book in digital format but I do not see the option on the O’Reilly site, only print version. Is it still available in e-book?


    • Eric Elliott - March 1, 2013

      Good timing – it’s 50% off right now. There is an option to buy the early release ebook. You’ll get the book in digital form, along with free updates as I add new content. Use the discount code “WKEARSE” (Expires March 7th).

    • asif usmani - September 23, 2013

      I just like intrested this.

  3. Eric, I missed the coupon date, any chance you can get me another one? I’m really interested in your book :D

    • Eric Elliott - April 6, 2013

      I’ll be on the lookout. I’ll post a reply here if there’s another promotion.

    • Eric Elliott - May 3, 2013

      Buy it TODAY and you’ll get 50% off.

  4. There’s a bug in chapter 3. You mentioned the problem in shopping cart code lies here:

    cart.items = Object.create(items);

    This is true if “items” property is object but in case of array it will fail. I am mentioning this because an array is passed to “createCart” method.

    // Hydrate cart with stored items.
    savedCart = createCart(["apple", "pear", "orange"]),

    • Eric Elliott - July 31, 2013

      Did you test the code?

      In JavaScript, an Array is mostly the same as an object.

      > var items = ["apple", "pear", "orange"];
      > foo = Object.create(items);
      > (item) { console.log(item); });

      I know. Weird. But it works.

      • When I tried this in chrome console it logged ‘[undefined, undefined, undefined]‘

        var items = ["apple", "pear", "orange"]; 
        var foo = Object.create(items); (item) { console.log(item); });

        but looks fine in jsbin or a standalone sample…

        • Eric Elliott - September 30, 2013

          It says ['undefined', 'undefined', 'undefined'] because we didn’t return anything from the map function. Notice though, it did log the item names, too. Change .map( to .forEach( if you don’t want to capture the new array and do something with the items. I used .map() because it’s usually more useful than .forEach() in that it returns an array of resulting values, so you can do something useful in your function without causing side-effects. For more on that, check out the functional programming and pure function sections from my book.

  5. Ron Grimes - January 7, 2014

    Could you please update your “Buy Now” link. It’s broken. 

    • Eric Elliott - February 12, 2014

      Thanks for the tip, Ron, I’ll see what I can do. In the mean time, a search for “Programming JavaScript Applications” on will take you to the right place to buy. I’ll figure out what happened, and try to get a permanent link hooked up ASAP.

  6. Hi, where can I buy the e-book?

    • Eric Elliott - February 20, 2014

      Currently, the e-book is the only option. Just click on the book cover in the upper right hand corner (or the big green “Buy now!” link). On that page under “Buying Options”, you should see “Immediate Access – Go Digital”. There are several ebook download options available, so you should be able to read it on any device. Enjoy!

      • bernhard schelling - March 1, 2014

        Hi, the Under Buing options where it says “Immediate Access – Go Digital”. there are no download options available :/ any hint?

Add Comment Register

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">