Home > Store > Open Source > Ajax & JavaScript
Programming in CoffeeScript
- By Mark Bates
- Published May 24, 2012 by Addison-Wesley Professional. Part of the Developer's Library series.
- Copyright 2012
- Dimensions: 7" x 9"
- Pages: 320
- Edition: 1st
- Book
- ISBN-10: 0-321-82010-X
- ISBN-13: 978-0-321-82010-5
Register your product to gain access to bonus material or receive a coupon.
Product Author Bios
Mark Bates is the founder and chief architect of the Boston-based consulting company Meta42 Labs. Mark spends his days focusing on new application development and consulting for his clients. At night he writes books, raises kids, and occasionally he forms a band and “tries to make it.”
Mark has been writing web applications, in one form or another, since 1996. His career starting as a UI developer writing HTML and JavaScript applications before moving toward the middle(ware) with Java and Ruby.
Always wanting to share his wisdom, or more correctly just wanting to hear the sound of his own voice, Mark has spoken at several high-profile conferences, including RubyConf and jQueryConf. Mark has also taught classes on Ruby and Ruby on Rails. In 2009 Mark’s first (surprisingly not his last!) book, Distributed Programming with Ruby, was published by Addison-Wesley.
Mark lives just outside of Boston with his wife, Rachel, and their two sons, Dylan and Leo. Mark can be found on the web at: http://www.markbates.com, http://twitter.com/markbates, and http://github.com/markbates
Use CoffeeScript to Write Better JavaScript Code Than Ever Before!
If you can do it in JavaScript, you can do it better in CoffeeScript. And, since CoffeeScript “compiles down” to JavaScript, your code will fit neatly into virtually any web environment. In Programming in CoffeeScript, Mark Bates shows web developers why CoffeeScript is so useful and how it avoids the problems that often make JavaScript code buggy and unmanageable. He guides you through every feature and technique you need to write quality CoffeeScript code and shows how to take advantage of CoffeeScript’s increasingly robust toolset.
Bates begins with the absolute basics of running and compiling CoffeeScript and then introduces syntax, control structures, functions, collections, and classes. Through same page code comparisons, you’ll discover exactly how CoffeeScript improves on JavaScript. Next, you’ll put it to work in building applications that are powerful, flexible, maintainable, concise, reliable, and secure. Bates shares valuable tips for better development, illuminating CoffeeScript’s hidden gems and warning you about its remaining “rough edges.” The book concludes with a start-to-finish application case study showing how to code back-ends and front-ends and integrate powerful frameworks and libraries. Coverage includes
- Understanding the right ways to compile and execute CoffeeScript
- Using CoffeeScript’s clean syntax to focus on your code, not JavaScript’s distractions
- Working with CoffeeScript’s control structures, functions, and arguments
- Taking full advantage of CoffeeScript’s implementation of collections and iterators
- Leveraging CoffeeScript’s full class support to create complex data models
- Automating common application development tasks with Cake and Cakefiles
- Configuring Jasmine with CoffeeScript support, and using it to systematically test your code
- Writing Node.js server-side applications in CoffeeScript
- Using CoffeeScript to write jQuery and Backbone.js applications
- Integrating framework code to avoid “reinventing the wheel”
Want a better way to create the JavaScript code your web applications need? CoffeeScript is the solution–and this book will help you master it!
Related Articles
"The Best Programming Advice I Ever Got" with Mark Bates
Testing Your JavaScript/CoffeeScript, Part 1 of 2: Setting Up a Test Framework in Ruby on Rails
Testing Your JavaScript/CoffeeScript, Part 2 of 2: Writing Tests
Author's Site
Author suggested sites: www.metabates.com/
Companion Site
A link from Programming in CoffeeScript can be found here: http://www.metabates.com/books/.
|
7 of 7 people found the following review helpful
By Joe Rama "360" (Seattle, WA USA) - See all my reviews
Amazon Verified Purchase(What's this?)
This review is from: Programming in CoffeeScript (Developer's Library) (Paperback)
"Programming in CoffeeScript" is solid and sets a new standard for CoffeeScript coverage, and that's why I give it 4 stars. It also has pleasant pacing, and practical insights.( NEW 2012-11-13 However, I give Chapter 8, "Testing with Jasmine", a full 5 stars for solving the TDD problem in CoffeeScript. The one hiccup was that the matchers in the book were already outdated (!) since they'd been renamed. Once you know the discrepancy, the "fix" is trivial --- like a bunch of predictable typos, and coincidentally Bates provides the URL to Jasmine Matchers in note #11 at the end of chapter 8. For me, this chapter was worth the price of the book. Without hemming and hawing, Bates just points you in the right direction with a complete, convenient, and powerful TDD solution for CoffeeScript (& JS) --- including a headless test rig that works on the command line, optional colors for visibility, a TextMate bundle for convenient testing within editor (look Ma: No shell!),... Read more
4 of 4 people found the following review helpful
By
This review is from: Programming in CoffeeScript (Developer's Library) (Paperback)
I only knew a few things about CoffeeScript before reading this book. Now I feel more confident using this language even if I will need to use it in my projects to better understand it.The book has two parts: I) A detailed view of CoffeeScript commands and how CoffeeScript code is translated into JavaScript. This part I use as a reference. II) Create a small online to-do list from scratch. This part could have been another interesting book. I am a beginner in CoffeeScript and I learned a lot of things by seing how to use CoffeeScript with other technologies. You will learn a lot about CoffeeScript but that's not all there is in this book. You will also get a rapid tour of Node.js and Backbone.js. I would have loved to have this great book in my hands when I started with CoffeeScript. I guess you will probably love CoffeeScript when you have finished this book. Now it's time to use all this knowledge to build better online services... Read more By
This review is from: Programming in CoffeeScript (Developer's Library) (Paperback)
Ok, Ok, i get the point in showing the generated javascript for a given chunk of coffeescript code ------- but by God, ALWAYS showing the generated javascript, no matter how big or ugly it is, is not only an eyesore, it's actually unhelpful, distracting and unnecessary. Every time i flick to a random page i just find a lump of ugly generated javascript glaring back at me. Isn't this meant to be a frikkin book about coffeescript? *some* of the time the generated code can be enlightening, but there's just too much of it and most of the time it's totally unhelpful.I've tried multiple times to read this book, but have just become annoyed with it. I highly recommended 'the little book of coffeescript' over this frustrating thing any day. |
› See all 5 customer reviews...
Online Sample Chapter
How to Use Functions and Arguments in CoffeeScript
Table of Contents
Dedication v
Acknowledgments xii
About the Author xiv
Preface xv
What Is CoffeeScript? xvii
Who Is This Book For? xix
How to Read This Book xix
How This Book Is Organized xxi
Part I: Core CoffeeScript xxii
Part II: CoffeeScript in Practice xxii
Installing CoffeeScript xxiii
How to Run the Examples xxiii
Notes xxiv
Part I: Core CoffeeScript
1 Getting Started 3
The CoffeeScript REPL 3
In-Browser Compilation 6
Caveats 7
Command-Line Compilation 7
The compile Flag 7
The CoffeeScript CLI 8
The output Flag 9
The bare Flag 9
The print Flag 10
The watch Flag 10
Executing CoffeeScript Files 11
Other Options 11
Wrapping Up 12
Notes 12
2 The Basics 13
Syntax 13
Significant Whitespace 14
Function Keyword 16
Parentheses 16
Scope and Variables 18
Variable Scope in JavaScript 18
Variable Scope in CoffeeScript 19
The Anonymous Wrapper Function 20
Interpolation 23
String Interpolation 23
Interpolated Strings 23
Literal Strings 25
Heredocs 28
Comments 29
Inline Comments 29
Block Comments 30
Extended Regular Expressions 31
Wrapping Up 31
Notes 32
3 Control Structures 33
Operators and Aliases 33
Arithmetic 33
Assignment 35
Comparison 39
String 42
The Existential Operator 43
Aliases 46
The is and isnt Aliases 47
The not Alias 48
The and and or Aliases 49
The Boolean Aliases 50
The @ Alias 51
If/Unless 52
The if Statement 53
The if/else Statement 54
The if/else if Statement 56
The unless Statement 58
Inline Conditionals 60
Switch/Case Statements 60
Wrapping Up 63
Notes 63
4 Functions and Arguments 65
Function Basics 68
Arguments 70
Default Arguments 72
Splats... 75
Wrapping Up 79
Notes 79
5 Collections and Iterations 81
Arrays 81
Testing Inclusion 83
Swapping Assignment 85
Multiple Assignment aka Destructing Assignment 86
Ranges 90
Slicing Arrays 92
Replacing Array Values 94
Injecting Values 95
Objects/Hashes 96
Getting/Setting Attributes 101
Destructuring Assignment 103
Loops and Iteration 105
Iterating Arrays 105
The by Keyword 106
The when Keyword 107
Iterating Objects 108
The by Keyword 109
The when Keyword 109
The own Keyword 110
while Loops 113
until Loops 114
Comprehensions 116
The do Keyword 119
Wrapping Up 120
Notes 121
6 Classes 123
Defining Classes 123
Defining Functions 125
The constructor Function 126
Scope in Classes 127
Extending Classes 137
Class-Level Functions 145
Prototype Functions 150
Binding (-> Versus =>) 151
Wrapping Up 158
Notes 158
Part II: CoffeeScript in Practice
7 Cake and Cakefiles 161
Getting Started 161
Creating Cake Tasks 162
Running Cake Tasks 163
Using Options 163
Invoking Other Tasks 167
Wrapping Up 169
Notes 170
8 Testing with Jasmine 171
Installing Jasmine 172
Setting Up Jasmine 172
Introduction to Jasmine 175
Unit Testing 176
Before and After 181
Custom Matchers 187
Wrapping Up 190
Notes 191
9 Intro to Node.js 193
What Is Node.js? 193
Installing Node 194
Getting Started 195
Streaming Responses 197
Building a CoffeeScript Server 199
Trying Out the Server 214
Wrapping Up 215
Notes 215
10 Example: Todo List Part 1 (Server-side) 217
Installing and Setting Up Express 218
Setting Up MongoDB Using Mongoose 222
Writing the Todo API 225
Querying with Mongoose 226
Finding All Todos 227
Creating New Todos 228
Getting, Updating, and Destroying a Todo 230
Cleaning Up the Controller 232
Wrapping Up 236
Notes 236
11 Example: Todo List Part 2 (Client-side w/ jQuery) 237
Priming the HTML with Twitter Bootstrap 237
Interacting with jQuery 240
Hooking Up the New Todo Form 242
Cleaning Up the Todo List with Underscore.js
Templates 244
Listing Existing Todos 247
Updating Todos 248
Deleting Todos 252
Wrapping Up 253
Notes 253
12 Example: Todo List Part 3 (Client-side w/ Backbone.js) 255
What Is Backbone.js? 255
Cleaning Up 256
Setting Up Backbone.js 256
Writing our Todo Model and Collection 260
Listing Todos Using a View 263
Creating New Todos 265
A View per Todo 268
Updating and Validating Models from Views 270
Validation 272
Deleting Models from Views 273
Wrapping Up 275
Notes 275
Index 277
Sample Pages
Download the sample pages (includes Chapter 4 and Index)

This book includes free shipping!
This book includes free shipping!
eBook (Watermarked)
$31.99
$25.59
Includes EPUB, MOBI, and PDF
About eBook Formats
This eBook includes the following formats, accessible from your Account page after purchase:
EPUBThe open industry format known for its reflowable content and usability on supported mobile devices.
MOBIThe eBook format compatible with the Amazon Kindle and Amazon Kindle applications.
PDFThe popular standard, used most often with the free Adobe® Reader® software.
This eBook requires no passwords or activation to read. We customize your eBook by discretely watermarking it with your name, making it uniquely yours.
- Request an Instructor or Media review copy.
- Corporate, Academic, and Employee Purchases
- International Buying Options
Get access to thousands of books and training videos about technology, professional development and digital media from more than 40 leading publishers, including Addison-Wesley, Prentice Hall, Cisco Press, IBM Press, O'Reilly Media, Wrox, Apress, and many more. If you continue your subscription after your 30-day trial, you can receive 30% off a monthly subscription to the Safari Library for up to 12 months. That's a total savings of $199.

