Async JavaScript: Build More Responsive Apps with Less Code (Pragmatic Express)

Async JavaScript: Build More Responsive Apps with Less Code (Pragmatic Express)

Trevor Burnham

Language: English

Pages: 104

ISBN: 1937785270

Format: PDF / Kindle (mobi) / ePub


With the advent of HTML5, front-end MVC, and Node.js, JavaScript is ubiquitous--and still messy. This book will give you a solid foundation for managing async tasks without losing your sanity in a tangle of callbacks. It's a fast-paced guide to the most essential techniques for dealing with async behavior, including PubSub, evented models, and Promises. With these tricks up your sleeve, you'll be better prepared to manage the complexity of large web apps and deliver responsive code.

With Async JavaScript, you'll develop a deeper understanding of the JavaScript language. You'll start with a ground-up primer on the JavaScript event model--key to avoiding many of the most common mistakes JavaScripters make. From there you'll see tools and design patterns for turning that conceptual understanding into practical code.

The concepts in the book are illustrated with runnable examples drawn from both the browser and the Node.js server framework, incorporating complementary libraries including jQuery, Backbone.js, and Async.js. You'll learn how to create dynamic web pages and highly concurrent servers by mastering the art of distributing events to where they need to be handled, rather than nesting callbacks within callbacks within callbacks.

Async JavaScript will get you up and running with real web development quickly. By the time you've finished the Promises chapter, you'll be parallelizing Ajax requests or running animations in sequence. By the end of the book, you'll even know how to leverage Web Workers and AMD for JavaScript applications with cutting-edge performance. Most importantly, you'll have the knowledge you need to write async code with confidence.

What You Need:

Basic knowledge of JavaScript is recommended. If you feel that you're not up to speed, see the "Resources for Learning JavaScript" section in the preface.

Bandit Algorithms for Website Optimization

Android for Programmers: An App-Driven Approach (Deitel Developer Series)

One Billion Rising: Law, Land and the Alleviation of Global Poverty

JavaScript Enlightenment

Oxford Handbook of Developmental Behavioral Neuroscience (Oxford Library of Neuroscience)

Pro PHP MVC

 

 

 

 

 

 

 

 

 

 

 

 

updating the DOM and the server when their states change. Storing mutable data in evented models is a great first step to reigning in the growing complexity of client-side JavaScript applications. 2.3 Custom jQuery Events Custom events are an underappreciated feature of jQuery that make it easy to graft a powerful distributed event system onto any web app, with no additional libraries. You can emit any event you want from any DOM element from jQuery using trigger. ​​$('#tabby,

the process with Ctrl+C.) As with web workers, the API is symmetric, with a send call on one side triggering a ’message’ event on the other side. But notice that the argument to send (or rather, a serialized copy) is given directly by the ’message’ event, rather than being attached as the data property. Notice the line ​​if (message._queryId) return;​​ in the master message handler? Node sometimes sends its own messages from the workers, which always look something like this: ​​{ cmd:

​​ ​​​​ ​​ ​​ ​​ ​​ ​​​​ ​​​​ ​​ ​​ ​​​​ ​​​​ Just remember that it’s important to wrap deferredScripts so that it won’t run until after the document ready event in browsers that don’t support defer. If the body content is more than a couple of kilobytes, that

forks Coco and LiveScript have a similar feature, which it calls backcalls. In Coco/LiveScript, the previous example would be written like this: ​​<- $​​ ​​alert 'The document is ready'​​ The Kaffeine/Coco/LiveScript approach provides much of the power of TameJS/StratifiedJS, with less of a learning curve. A1.4 Streamline.js Like Kaffeine, Streamline.js[65] provides a special syntax for transforming the code after an async function call into its callback. Just use _ in place of the

type="application/javascript;version=1.7" >​​ If generators appeal to you, there is a tool that allows you to compile code that uses generators (and other ECMAScript 5+ features) into widely supported JavaScript code: Google’s Traceur.[66] Footnotes [62] https://twitter.com/jeresig/statuses/164496725254479872 [63] https://github.com/onilabs/apollo [64] http://weepy.github.com/kaffeine/index.html [65] https://github.com/Sage/streamlinejs [66]

Download sample

Download