did-you-know? rent-now

Amazon no longer offers textbook rentals. We do!

did-you-know? rent-now

Amazon no longer offers textbook rentals. We do!

We're the #1 textbook rental company. Let us show you why.

9780321820105

Programming in Coffeescript

by
  • ISBN13:

    9780321820105

  • ISBN10:

    032182010X

  • Edition: 1st
  • Format: Paperback
  • Copyright: 2012-05-24
  • Publisher: Addison-Wesley Professional
  • Purchase Benefits
  • Free Shipping Icon Free Shipping On Orders Over $35!
    Your order must be $35 or more to qualify for free economy shipping. Bulk sales, PO's, Marketplace items, eBooks and apparel do not qualify for this offer.
  • eCampus.com Logo Get Rewarded for Ordering Your Textbooks! Enroll Now
List Price: $39.99 Save up to $4.00
  • Digital
    $35.99
    Add to Cart

    DURATION
    PRICE

Supplemental Materials

What is included with this book?

Summary

For millions of web developers, CoffeeScript is emerging as one of today's most exciting new technologies. A superset of JavaScript, it enables experienced Javascript developers to write better, clearer code: software that's more concise, maintainable, flexible, reliable, and secure. CoffeeScript's inclusion in the popular web framework, Ruby on Rails, has brought CoffeeScript to an immense new audience. Programming in CoffeeScriptcovers everything experienced web developers need to evaluate CoffeeScript, "think" in CoffeeScript, and write high-performance software with it. Mark Bates follows the proven format of other "Programming in" books in our Developers'Library series, with one major addition: he presents multiple same-page code comparisons demonstrating exactly how CoffeeScript improves upon JavaScript. Both a tutorial and reference, this book first introduces CoffeeScript's basic concepts, and then shows how to build a full fledged application with it. Bates covers functions, scope, collections, iterations, classes, modules, CoffeeScript's innovative Cake build system testing with the popular Jasmine framework, and much more - concluding with a full application that uses CoffeeScript on both the server side, using popular tools such as Express, Node.js, and Mongoose (MongoDB), and the client side, with jQuery and Backbone.js.

Author Biography

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 started as a UI developer writing HTML and JavaScript applications before moving toward the middle(ware) with Java and Ruby. Nowadays, Mark spends his days cheating on Ruby with his new mistress, CoffeeScript.

 

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, RailsConf, 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.

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    2 77

 

 

Supplemental Materials

What is included with this book?

The New copy of this book will include any supplemental materials advertised. Please check the title of the book to determine if it should include any access cards, study guides, lab manuals, CDs, etc.

The Used, Rental and eBook copies of this book are not guaranteed to include any supplemental materials. Typically, only the book itself is included. This is true even if the title states it includes any access cards, study guides, lab manuals, CDs, etc.

Rewards Program