Publishers Acknowledgements
Some of the people who helped bring this book to market include the following:
Editorial and Production
VP Consumer and Technology Publishing Director: Michelle Leete
Associate DirectorBook Content Management: Martin Tribe
Associate Publisher: Chris Webb
Executive Commissioning Editor: Birgit Gruber
Associate Commissioning Editor: Ellie Scott
Development Editor: Sydney Argenta
Copy Editor: Melba Hopper
Technical Editor: Kevin Bradwick
Editorial Manager: Jodi Jensen
Senior Project Editor: Sara Shlaer
Editorial Assistant: Annie Sullivan
Marketing
Associate Marketing Director: Louise Breinholt
Marketing Manager: Lorna Mein
Senior Marketing Executive: Kate Parrett
Marketing Assistant: Tash Lee
Composition Services
Compositor: Indianapolis Composition Services
Proofreader: Lindsay Amones
Indexer: Potomac Indexing, LLC
This edition first published 2013
2013 John Wiley & Sons, Ltd.
Registered office
John Wiley & Sons Ltd, The Atrium, Southern Gate, Chichester, West Sussex, PO19 8SQ, United Kingdom
For details of our global editorial offices, for customer services and for information about how to apply for permission to reuse the copyright material in this book please see our website at www.wiley.com.
The right of the author to be identified as the author of this work has been asserted in accordance with the Copyright, Designs and Patents Act 1988.
All rights reserved. No part of this publication may be reproduced, stored in a retrieval system, or transmitted, in any form or by any means, electronic, mechanical, photocopying, recording or otherwise, except as permitted by the UK Copyright, Designs and Patents Act 1988, without the prior permission of the publisher.
Wiley also publishes its books in a variety of electronic formats. Some content that appears in print may not be available in electronic books.
Designations used by companies to distinguish their products are often claimed as trademarks. All brand names and product names used in this book are trade names, service marks, trademarks or registered trademarks of their respective owners. The publisher is not associated with any product or vendor mentioned in this book. This publication is designed to provide accurate and authoritative information in regard to the subject matter covered. It is sold on the understanding that the publisher is not engaged in rendering professional services. If professional advice or other expert assistance is required, the services of a competent professional should be sought.
Trademarks: Wiley and the John Wiley & Sons, Ltd. logo are trademarks or registered trademarks of John Wiley and Sons, Inc. and/ or its affiliates in the United States and/or other countries, and may not be used without written permission. All other trademarks are the property of their respective owners. John Wiley & Sons, Ltd. is not associated with any product or vendor mentioned in the book.
978-1-118-45437-4
A catalogue record for this book is available from the British Library.
ISBN 978-1-118-45437-4 (paperback); ISBN 978-1-118-45492-3 (ebook); ISBN 978-1-118-45493-0 (ebook); ISBN 978-1-118-45494-7 (ebook)
Set in 10/12 Minion Pro Regular by Indianapolis Composition Services
Printed in the U.K. by Bell & Bain
For Laura & Ben
About the Author
Alex Hudsons first computers comprised an Amstrad 1512 and Oric Atmos: two peculiarly British machines, coming with slightly odd versions of BASIC. As was the case with most 8-bit machines of that era, they also arrived with programming manuals and assembly language instruction set documentation, and from that point on Alex was hooked.
By his teens, the Internet had happened: or, at least, dial-up CompuServe access arrived in the UK. With a group of like-minded friends who enjoyed swapping code, now on the peculiarly British Psion 3a portable computer, Alex won one of the first national awards for a schools websitein hindsight, probably due more to lack of competition than technical innovation.
Swapping code on the internet turned out to be the next big thing, and Alex became an active member of the UK free software and open source community, developing applications and libraries and actively contributing to a number of different projects, including Linux, Hula (later Bongo), and later became a Fedora Developer.
Alex has a broad background in information systems. From leading development of innovative foreign language e-learning systems to large databases for Government projects, the common theme in his work life has been digital application development. Having co-founded and advised a number of start-ups, he currently serves as the Chief Technical Officer at mydeco.com, an innovative homewares start-up making big strides in Europe.
Acknowledgments
To begin with, Id like to thank the wonderful team at Wiley: firstly, Chris Webb for reaching out to me in the first place but then being incredibly positive about the various ideas I pitched to him. Secondly, to Sydney Jones Argenta, whose tolerance and patience with me has been out-matched only by her skilled leadership of this project, and without whom this book wouldnt have happened. I also need to thank the various editors and reviewers who spent their time on my manuscripts, this book is so much the better for their work.
A large proportion of this book covers CoffeeScript, jQuery, and Spine; software authored largely (to begin with, at least) by three individuals: Jeremy Ashkenas, John Resig and Alex MacCaw, respectively. They deserve not only my thanks for their prolific technical authorship (beyond even those projects mentioned), but broader recognition of their contribution to the Internet and technology in general. The world needs more inspirational coders of their ilk.
Lastly, I need to thank my family for providing the time and space to write. My wife is my constant support, and my parents, sister and various in-laws have all been tremendously encouraging. I have a new-found respect for those who commit to writing a book but also for their families, whose contribution is difficult to overstate.
If you have bought this book, or at least picked it up because it interested you, then you have at least heard of CoffeeScript and have an inkling of what the language is. In the words of its author, CoffeeScript is a little language that compiles into JavaScript, and in a sense, that is all you need to know about the language. But a number of more profound ideas follow from that simple concept.
To understand CoffeeScript properly, its important to understand the history of JavaScript. In the early days of Netscape Navigator, an engineer by the name of Brendan Eich was given the task of writing a scripting language that the browser would interpret, along with only two guiding principles. First, the language needed to look like Java, because that was the cool language at the time. Second, he had only ten days to write a functioning implementation.
That was a tremendously tall order but one that Eich was equal to. He created a small, language that fulfilled looked and acted like Java, called Mocha. Additionally, he made decisions that set the language apart from others, such as treating functions as first-class objects that could be passed around at will and using prototypical object inheritance rather than the classical style preferred by the likes of C++ and Java. JavaScript, as it was eventually called, saw its first release in 1995 as part of Netscape Navigator 2.0.