Programming in CoffeeScript

Book description

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!


    Table of contents

    1. Title Page
    2. Copyright Page
    3. Developer’s Library
    4. Dedication
    5. Contents at a Glance
    6. Table of Contents
    7. Acknowledgments
    8. About the Author
    9. Preface
      1. What Is CoffeeScript?
      2. Who Is This Book For?
      3. How to Read This Book
      4. How This Book Is Organized
      5. Installing CoffeeScript
      6. How to Run the Examples
      7. Notes
    10. Part I. Core CoffeeScript
      1. 1. Getting Started
        1. The CoffeeScript REPL
        2. In-Browser Compilation
        3. Caveats
        4. Command-Line Compilation
        5. The CoffeeScript CLI
        6. Wrapping Up
        7. Notes
      2. 2. The Basics
        1. Syntax
        2. Scope and Variables
        3. Interpolation
        4. Extended Regular Expressions
        5. Wrapping Up
        6. Notes
      3. 3. Control Structures
        1. Operators and Aliases
        2. If/Unless
        3. Switch/Case Statements
        4. Wrapping Up
        5. Notes
      4. 4. Functions and Arguments
        1. Function Basics
        2. Arguments
        3. Default Arguments
        4. Splats...
        5. Wrapping Up
        6. Notes
      5. 5. Collections and Iterations
        1. Arrays
        2. Ranges
        3. Objects/Hashes
        4. Loops and Iteration
        5. Comprehensions
        6. The do Keyword
        7. Wrapping Up
        8. Notes
      6. 6. Classes
        1. Defining Classes
        2. Defining Functions
        3. The constructor Function
        4. Scope in Classes
        5. Extending Classes
        6. Class-Level Functions
        7. Prototype Functions
        8. Binding (-> Versus =>)
        9. Wrapping Up
        10. Notes
    11. Part II. CoffeeScript in Practice
      1. Notes
      2. 7. Cake and Cakefiles
        1. Getting Started
        2. Creating Cake Tasks
        3. Running Cake Tasks
        4. Using Options
        5. Invoking Other Tasks
        6. Wrapping Up
        7. Notes
      3. 8. Testing with Jasmine
        1. Installing Jasmine
        2. Setting Up Jasmine
        3. Introduction to Jasmine
        4. Unit Testing
        5. Before and After
        6. Custom Matchers
        7. Wrapping Up
        8. Notes
      4. 9. Intro to Node.js
        1. What Is Node.js?
        2. Installing Node
        3. Getting Started
        4. Streaming Responses
        5. Building a CoffeeScript Server
        6. Trying Out the Server
        7. Wrapping Up
        8. Notes
      5. 10. Example: Todo List Part 1 (Server-side)
        1. Installing and Setting Up Express
        2. Setting Up MongoDB Using Mongoose
        3. Writing the Todo API
        4. Querying with Mongoose
        5. Wrapping Up
        6. Notes
      6. 11. Example: Todo List Part 2 (Client-side w/ jQuery)
        1. Priming the HTML with Twitter Bootstrap
        2. Interacting with jQuery
        3. Hooking Up the New Todo Form
        4. Listing Existing Todos
        5. Updating Todos
        6. Deleting Todos
        7. Wrapping Up
        8. Notes
      7. 12. Example: Todo List Part 3 (Client-side w/ Backbone.js)
        1. What Is Backbone.js?
        2. Setting Up Backbone.js
        3. Writing our Todo Model and Collection
        4. Listing Todos Using a View
        5. Creating New Todos
        6. A View per Todo
        7. Deleting Models from Views
        8. Wrapping Up
        9. Notes
    12. Index

    Product information

    • Title: Programming in CoffeeScript
    • Author(s):
    • Release date: May 2012
    • Publisher(s): Addison-Wesley Professional
    • ISBN: 9780132946155