Book Image

CoffeeScript Application Development

By : Ian Greenleaf Young
Book Image

CoffeeScript Application Development

By: Ian Greenleaf Young

Overview of this book

JavaScript is becoming one of the key languages in web development. It is now more important than ever across a growing list of platforms. CoffeeScript puts the fun back into JavaScript programming with elegant syntax and powerful features. CoffeeScript Application Development will give you an in-depth look at the CoffeeScript language, all while building a working web application. Along the way, you'll see all the great features CoffeeScript has to offer, and learn how to use them to deal with real problems like sprawling codebases, incomplete data, and asynchronous web requests. Through the course of this book you will learn the CoffeeScript syntax and see it demonstrated with simple examples. As you go, you'll put your new skills into practice by building a web application, piece by piece. You'll start with standard language features such as loops, functions, and string manipulation. Then, we'll delve into advanced features like classes and inheritance. Learn advanced idioms to deal with common occurrences like external web requests, and hone your technique for development tasks like debugging and refactoring. CoffeeScript Application Development will teach you not only how to write CoffeeScript, but also how to build solid applications that run smoothly and are a pleasure to maintain.
Table of Contents (19 chapters)
CoffeeScript Application Development
Credits
About the Author
Acknowledgements
About the Reviewers
www.PacktPub.com
Preface
Index

Understanding asynchronous operations


It's a word you've probably heard before, but may not understand exactly what it means or why we care. Asynchronous operations are operations that do not block while completing. What does that mean, exactly? Well, synchronous operations (the vast majority of commands in a program) get executed one at a time, in order. Consider this code:

mixBatter()
bakeCake()
frostCake()

Each of these functions is invoked in order, and not until the previous function returns. bakeCake is only invoked after mixBatter returns, and frostCake is invoked only after bakeCake returns. If bakeCake takes 40 minutes to return, well, frostCake will have to wait 40 minutes before it can run. We could say that bakeCake blocks execution until it is finished.

This makes the code very easy to reason about, and most of the time it's the behavior that we want. However, there are times where we might wish to start an operation but not wait for it to finish before doing more work. Most often...