Smashing CoffeeScript

Overview

Brew the perfect code with CoffeeScript

If you're familiar with JavaScript and the often-frustrating process of creating complex applications, a nice cup of CoffeeScript can help. CoffeeScript is a programming language that compiles into JavaScript and simplifies the entire development process. Now you can tap the full power of CoffeeScript with Smashing CoffeeScript. This full-color, practical book explains CoffeeScript language, syntax, and processes, and will soon have you ...

See more details below
Paperback
$32.28
BN.com price
(Save 28%)$44.99 List Price

Pick Up In Store

Reserve and pick up in 60 minutes at your local store

Other sellers (Paperback)
  • All (13) from $23.60   
  • New (10) from $23.60   
  • Used (3) from $24.00   

Overview

Brew the perfect code with CoffeeScript

If you're familiar with JavaScript and the often-frustrating process of creating complex applications, a nice cup of CoffeeScript can help. CoffeeScript is a programming language that compiles into JavaScript and simplifies the entire development process. Now you can tap the full power of CoffeeScript with Smashing CoffeeScript. This full-color, practical book explains CoffeeScript language, syntax, and processes, and will soon have you producing concise and quality code. Ultimately, you'll create RIAs and mobile apps faster, with less hassle.

  • Gets developers up and running on CoffeeScript, a programming language that compiles into JavaScript and simplifies the process of building software
  • Helps you produce better JavaScript and more quickly
  • Introduces the language, syntax, and processes of CoffeeScript
  • Covers the development of both mobile and rich internet apps
  • Explores the HTML5 feature set, real-time communication, and using CoffeeScript within node.js projects

Developers, blend some better JavaScript with CoffeeScript and Smashing CoffeeScript.

Read More Show Less

Product Details

  • ISBN-13: 9781118454374
  • Publisher: Wiley
  • Publication date: 5/6/2013
  • Series: Smashing Magazine Book Series
  • Edition number: 1
  • Pages: 336
  • Sales rank: 1,408,730
  • Product dimensions: 7.40 (w) x 9.20 (h) x 0.80 (d)

Meet the Author

Alex Hudson is a technology expert and programmer. A hacker by trade, he likes to keep on top of new technologies. He hacks in C, C#, JavaScript, Perl, PHP, Python, and Vala Primarily, and due to the day job has a keen interest in HTML5, CSS, SQL, and NoSQL.
Read More Show Less

Table of Contents

INTRODUCTION 1

PART I: COFFEESCRIPT BASICS 7

Chapter 1: Starting Up Your CoffeeScript Environment 9

CoffeeScript in the Browser 10

Starting CoffeeScript in Plain HTML 10

Understanding CoffeeScript 11

Compiling CoffeeScript Outside the Browser 12

What Is npm? 12

Installing Coffee Using npm 13

A Quick Tour of npm 13

Installing CoffeeScript 14

Compiling CoffeeScript Code 15

Putting It Together 16

Automatic Compilation 17

Avoiding Coff eeScript Errors 17

Coding in Good Style 18

Coffeelint Will Pick Up Errors 20

Summary 20

Chapter 2: Using jQuery: DOM Manipulation 21

jQuery’s Fluent API 22

Th e “DOM Ready” Handler 23

Selectors, Now Even More Usable 24

Comprehensions 25

Working with Functions 26

Functions for Encapsulation 28

Keeping Code DRY 31

Function Parameters and Existential Operators 32

Using Utility Functions 33

Cleaner Click Handlers 36

General Event Handling 37

Page Events 38

Feature Detection for Practical Polyfi ll 40

Detecting CSS Features 41

Summary 42

Chapter 3: Working with Forms 43

Basic HTML5 Forms 44

Collecting Form Data 44

Validating Form Data 45

Systematizing Validation 47

Common Form Techniques 49

Displaying Validation Results Inline 49

Continuous Validation 52

Controlling Submit Button Interaction 54

Prepopulating Form Elements 54

Multi-Step Forms 55

Selective Form Display 55

Validating Partial Form Data 59

Modal Form UI 59

Using Subforms as Data Helpers 61

Summary 62

Chapter 4: AJAX Requests 63

Getting Data to and from the Server 64

HTTP Requests 64

Easily Retrieving Information 66

Cross-origin Request Handling 68

Understanding Browser Request Security 68

JSONP Requests 69

Cross-Origin Resource Sharing 71

Example: User Registration Form 71

Error Handling 78

Generating Errors 79

Detecting Errors 80

Retrying in Case of Temporary Errors 81

Deferring and Cancelling Requests Using Queues 83

Strategies to Defer Requests 84

Strategies to Cancel Requests 86

Local Storage and Offl ine Apps 87

A Short History of Local Storage 87

LocalStorage 88

IndexedDB 90

Comparing Local Storage Options 92

Summary 92

Chapter 5: Object-Oriented Design 93

Classes and Inheritance 94

What Does It Mean To Be Object-Oriented? 94

Functions Versus Objects to Encapsulate 95

Extending Classes 97

Making Classes Substitutable 100

Using this. in Coff eeScript 101

Private and Protected Members 102

Mixins and Interfaces 102

Summary 103

PART II: COFFEESCRIPT PROJECTS 105

Chapter 6: Using Javascript Libraries 107

Easy Calling Conventions: Don’t Th row Away that Existing Code! 108

Calling JavaScript from Coff eeScript 108

Calling Coff eeScript from JavaScript 110

Using CommonJS Modules 111

Using Extends on Existing Classes 113

Not All Objects Are Created Equal 113

Writing Javascript Libraries in Coff eeScript 114

Providing a Natural Interface 114

Documenting Code 115

Mixing Javascript—When Absolutely Required 117

Summary 119

Chapter 7: Testing with Jasmine 121

Introducing Jasmine 122

Setting Up a Spec Area to Run Jasmine Tests 122

Writing Jasmine Tests 123

Spying with Jasmine 124

Behavior-Driven Development: What Is a Good Test? 126

Testing Inside the Browser 127

Conventions for Testing the UI 131

Driving jQuery 132

Fixtures 133

Summary 134

Chapter 8: Debugging CoffeeScript 135

Writing Reliable Software 136

Reading and Debugging CoffeeScript and JavaScript 136

Using Firebug 139

Using AceBug 142

Building Source Maps 143

Introducing CoffeeScript Redux 144

Using CoffeeScript Redux 145

Using Source Maps 146

Summary 150

Chapter 9: Building Resources with cake and hem 151

Tasks and the Cakefile 152

Starting with cake 152

Thinking about Project Directory Layout 153

Tests from cake 154

Compile Source into Single Files for Production Deployment 155

hem for Further Minification 156

Using Standardized Locations 157

Summary 158

PART III: COFFEESCRIPT APPLICATION DEVELOPMENT 159

Chapter 10: Writing Applications with Spine 161

Introducing Spine 162

Creating a New Spine Application 163

Building the Application 169

Preparing the Ground 170

Removing jQueryify 171

Styling an Application with Stylus 172

Working with Stylus 172

Taking a Deeper Look at Stylus Features 174

Spine’s Default Styls 177

Starting with Controllers 180

Testing Controllers 181

Controlling the Page 182

Adding Controllers 185

Stacking Controllers 186

Viewing the Results 188

Using (j)Eco Templates 188

Data Binding 190

Modelling Client-Side Data 193

Creating a Spine Model 193

Working with Models 195

Triggering Model Events 196

Validating Models 198

Editing Model Data 199

Storing Data on the Server 202

Summary 204

Chapter 11: Writing jQuery Plug-ins 205

Anatomy of a jQuery Plug-in 206

Creating a Skeleton Plug-in 206

Writing a Classful Plug-in 209

Handling Events and Behavior 211

Attaching the Plug-in to jQuery 213

Inheriting from an Existing Plug-in 214

jQuery UI 215

Using Widgets Instead of Plug-ins 215

Writing a Tagging Component 218

Bridging the Divide 222

Summary 225

Chapter 12: Mobile Coff eeScript Applications 227

Understanding Mobile First Principles 228

jQuery and Mobile Applications 229

Spine.mobile 230

Creating an e-Commerce Shop 234

Providing a Product Listing 238

Bringing in jQuery Mobile 243

Jumping and History 250

Summary 254

PART IV: ADVANCED COFFEESCRIPT 255

Chapter 13: Data Bindings and Form Elements 257

One-Way Bindings onto Form Views 258

A Simple Binding Interface 258

Setting Form Data 260

Two-Way Bindings 261

The Infamous “Getter Setter” Pattern 262

Implicit Getter/Setter 264

Observing Changes 265

Dynamic Form Building 268

Form as Model, View, and Controller 270

Summary 270

Chapter 14: Server-Side CoffeeScript 271

Putting Coff ee in the Server 272

Node.js and Coff eeScript 272

Writing a Simple Server 273

Using MongoDB 273

Architecting with MVC 274

Introducing Express.js 275

Responding to Client Requests 279

Rendering Views 280

Controlling Responses 281

Securing the Application 287

Summary 290

Chapter 15: Real-Time Web with socket.io 291

Defi ning Real-Time Applications 292

Polling the Server for Data 292

Comet for Lightweight Polling 293

Server-Side Events and Web Sockets 293

Doing Micro-Blogging in Real Time 294

Integrating Static and Real-Time Data 296

Rendering on the Client Side 296

Reusing Server-Side Code on the Client 298

Sharing Templates 298

Sharing Models 299

Dealing with Callback Pyramids 299

Real-Time Collaboration within a Single App 301

Operational Transformation 302

Separating Input from Operation 302

Building a Meeting Whiteboard App 303

Modeling Information According to OT 306

Serving Simple socket.io Information 307

Handling Remote Updates 308

Summary 311

Index 313

Read More Show Less

Customer Reviews

Be the first to write a review
( 0 )
Rating Distribution

5 Star

(0)

4 Star

(0)

3 Star

(0)

2 Star

(0)

1 Star

(0)

Your Rating:

Your Name: Create a Pen Name or

Barnes & Noble.com Review Rules

Our reader reviews allow you to share your comments on titles you liked, or didn't, with others. By submitting an online review, you are representing to Barnes & Noble.com that all information contained in your review is original and accurate in all respects, and that the submission of such content by you and the posting of such content by Barnes & Noble.com does not and will not violate the rights of any third party. Please follow the rules below to help ensure that your review can be posted.

Reviews by Our Customers Under the Age of 13

We highly value and respect everyone's opinion concerning the titles we offer. However, we cannot allow persons under the age of 13 to have accounts at BN.com or to post customer reviews. Please see our Terms of Use for more details.

What to exclude from your review:

Please do not write about reviews, commentary, or information posted on the product page. If you see any errors in the information on the product page, please send us an email.

Reviews should not contain any of the following:

  • - HTML tags, profanity, obscenities, vulgarities, or comments that defame anyone
  • - Time-sensitive information such as tour dates, signings, lectures, etc.
  • - Single-word reviews. Other people will read your review to discover why you liked or didn't like the title. Be descriptive.
  • - Comments focusing on the author or that may ruin the ending for others
  • - Phone numbers, addresses, URLs
  • - Pricing and availability information or alternative ordering information
  • - Advertisements or commercial solicitation

Reminder:

  • - By submitting a review, you grant to Barnes & Noble.com and its sublicensees the royalty-free, perpetual, irrevocable right and license to use the review in accordance with the Barnes & Noble.com Terms of Use.
  • - Barnes & Noble.com reserves the right not to post any review -- particularly those that do not follow the terms and conditions of these Rules. Barnes & Noble.com also reserves the right to remove any review at any time without notice.
  • - See Terms of Use for other conditions and disclaimers.
Search for Products You'd Like to Recommend

Recommend other products that relate to your review. Just search for them below and share!

Create a Pen Name

Your Pen Name is your unique identity on BN.com. It will appear on the reviews you write and other website activities. Your Pen Name cannot be edited, changed or deleted once submitted.

 
Your Pen Name can be any combination of alphanumeric characters (plus - and _), and must be at least two characters long.

Continue Anonymously

    If you find inappropriate content, please report it to Barnes & Noble
    Why is this product inappropriate?
    Comments (optional)