Programming in CoffeeScript
Mark Bates
Upper Saddle River, NJ Boston Indianapolis San Francisco
New York Toronto Montreal London Munich Paris Madrid
Cape Town Sydney Tokyo Singapore Mexico City
Programming in CoffeeScript
Copyright 2012 by Pearson Education, Inc.
All rights reserved. No part of this book shall be reproduced, stored in a retrieval system, or transmitted by any means, electronic, mechanical, photocopying, recording, or otherwise, without written permission from the publisher. No patent liability is assumed with respect to the use of the information contained herein. Although every precaution has been taken in the preparation of this book, the publisher and author assume no responsibility for errors or omissions. Nor is any liability assumed for damages resulting from the use of the information contained herein.
ISBN-13: 978-0-32-182010-5
ISBN-10: 0-32-182010-X
Library of Congress Cataloging-in-Publication Data is on file
Editor-in-Chief
Mark Taub
Acquisitions Editor
Debra Williams Cauley
Senior Development Editor
Chris Zahn
Managing Editor
Kristy Hart
Project Editor
Andy Beaster
Copy Editor
Barbara Hacha
Indexer
Tim Wright
Proofreader
Debbie Williams
Technical Editors
Stuart Garner
Dan Pickett
Publishing Coordinator
Olivia Basegio
Book Designer
Gary Adair
Compositor
Nonie Ratcliff
Trademarks
All terms mentioned in this book that are known to be trademarks or service marks have been appropriately capitalized. Pearson cannot attest to the accuracy of this information. Use of a term in this book should not be regarded as affecting the validity of any trademark or service mark.
Warning and Disclaimer
Every effort has been made to make this book as complete and as accurate as possible, but no warranty or fitness is implied. The information provided is on an as is basis. The author and the publisher shall have neither liability nor responsibility to any person or entity with respect to any loss or damages arising from the information contained in this book.
Bulk Sales
Pearson offers excellent discounts on this book when ordered in quantity for bulk purchases or special sales. For more information, please contact
U.S. Corporate and Government Sales
1-800-382-3419
For sales outside of the U.S., please contact
International Sales
Rachel, Dylan, and Leo: My life for you.
Developers Library
ESSENTIAL REFERENCES FOR PROGRAMMING PROFESSIONALS
Developers Library books are designed to provide practicing programmers with unique, high-quality references and tutorials on the programming languages and technologies they use in their daily work.
All books in the Developers Library are written by expert technology practitioners who are especially skilled at organizing and presenting information in a way thats useful for other programmers.
Key titles include some of the best, most widely acclaimed books within their topic areas:
PHP & MySQL Web Development
Luke Welling & Laura Thomson
ISBN 978-0-672-32916-6
MySQL
Paul DuBois
ISBN-13: 978-0-672-32938-8
Linux Kernel Development
Robert Love
ISBN-13: 978-0-672-32946-3
Python Essential Reference
David Beazley
ISBN-13: 978-0-672-32862-6
Programming in Objective-C
Stephen G. Kochan
ISBN-13: 978-0-321-56615-7
PostgreSQL
Korry Douglas
ISBN-13: 978-0-672-33015-5
Developers Library books are available at most retail and online bookstores, as well as by subscription from Safari Books Online at safari.informit.com
Developers Library
informit.com/devlibrary
I said it in my first book, and Ill say it again here: Writing a book is incredibly hard work! Please make sure no one ever tells you differently. If they do, they are either an incredible liar or Stephen King. Fortunately for me I fall somewhere in the middle.
Writing a book is simultaneously a very independent and solitary activity, as well as a team effort. After I put the kids to bed, I head down to my office, crack open a few Guinesses (is the plural Guinei?), crank up the tunes, and work, by myself, into the wee hours of the morning. When I finish a chapter, I send it off to my editor, who then sends it off to a bunch of people who take what I have written and improve it in ways that I didnt know possible. Whether its as simple as correcting grammar or spelling mistakes, to something more complex such as helping to improve the flow of the book, or point out where example code could be improved to further clarify a point. So, while the writing may be done alone in a dark room by yours truly, the final product is the culmination of many peoples hard work.
In this section of the book, I get the chance to say thank you to those who help shape, define, and otherwise ensure that the book you are currently holding (or downloading) is of the highest quality it can be. So without further adieu Im going to thank people Academy Awards style, knowing that Im sure Ive left someone off the list, for which I am incredibly sorry.
First and foremost I have to thank my beautiful wife, Rachel. Rachel is one of the most supportive and strong people I have ever met. Each night I get to crawl into bed beside her and each morning I get the joy of waking up next to her. I have the pleasure of staring into her eyes and seeing unconditional love there. I also get the encouragement to write books, start my own business, and to do whatever it is that will make me happiest in life. She gave me two handsome sons and in return Ive given her bad jokes and my used cell phones. I clearly got the better end of the bargain in this marriage, and for that I am eternally grateful.
Next, I would like to thank my sons, Dylan and Leo. While neither of them directly contributed to this book, they do make life worth living and they give my life an energy and excitement that only children can. I love you boys both so very much.
Before moving off the subject of my family, I would like to thank my parents (especially you Mom!) and the rest of my family for always being there to both simultaneously support me and cut me down to size. I love you all.
Next I have to thank Debra Williams Cauley. Debra was my editor, handler, and psychiatrist on my first book, Distributed Programming with Ruby. I can only hope that other authors have the fortune to work with an editor as good as Debra. She truly has the patience of a saint. I hope that should I ever write another book, Debra will be right there with me. I cant imagine writing a book without her. Thank you, Debra.
When writing a technical book, there are people that are very important to the process; they are the technical reviewers. A technical reviewers job is to read each chapter and critique it from a technical standpoint, as well as answer the question, Does it make sense to learn this here? These reviewers are there to act as your audience. They are technically minded and know their subject. Therefore, the feedback that you get from them is incredibly important. On this book there have a been a few technical reviewers. But the two I really want to call out are Stuart Garner and Dan Pickett. Stuart and Dan went way above the call of duty on this book and were by no means afraid of telling me when I did or said something boneheaded. They received frantic phone calls and emails from me at all hours of the day and night and responded with amazing feedback. If I didnt want all those sweet royalty checks all to myself I mightve been tempted to cut them in. (Dont worry, they got paid for their work. They each received a coupon for one free hour of Mark time.) Thank you Dan and Stuart, and the rest of the technical reviewers, for all of your hard work.