Book Image

Backbone.js Essentials

By : Jeremy Walker
Book Image

Backbone.js Essentials

By: Jeremy Walker

Overview of this book

<p>This book offers insight into creating and maintaining dynamic Backbone.js web applications. It delves into the the fundamentals of Backbone.js and helps you achieve mastery of the Backbone library.</p> <p>Starting with Models and Collections, you'll learn how to simplify client-side data management and easily transmit data to and from your server. Next, you'll learn to use Views and Routers to facilitate DOM manipulation and URL control so that your visitors can navigate your entire site without ever leaving the first HTML page. Finally, you'll learn how to combine those building blocks with other tools to achieve high-performance, testable, and maintainable web applications.</p>
Table of Contents (20 chapters)
Backbone.js Essentials
Credits
About the Author
Acknowledgments
About the Reviewers
www.PacktPub.com
Preface
Index

New syntax with CoffeeScript


You would think that as the creator of Backbone (and Underscore and Docco), Jeremy Ashkenas would have enough on his hands … but you'd be wrong. Somewhere in between creating these three libraries, Jeremy also found the time to create an entirely new programming language called CoffeeScript (http://coffeescript.org/).

CoffeeScript is interesting to many web developers because of the following two key features:

  1. CoffeeScript compiles to JavaScript, which means that you can use it for development but then compile it into a language that your user's browsers can actually understand.

  2. CoffeeScript offers a syntax and feature set that have more in common with languages such as Python or Ruby than with "vanilla" JavaScript.

This is best explained by example. Here's how you would create a View class for an h1 element in CoffeeScript:

class HeaderView extends Backbone.View
    tagName: 'h1'
    initialize: ->
        @render
    render: ->
        $(@el).text 'Hello...