Book Image

CoffeeScript Application Development Cookbook

By : Mike Hatfield
Book Image

CoffeeScript Application Development Cookbook

By: Mike Hatfield

Overview of this book

Table of Contents (18 chapters)
CoffeeScript Application Development Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Working with classes


Traditional classes do not exist in JavaScript. They can be very useful in decomposing your code into reusable component-like blocks. This is especially true if you are used to working with classes in other languages.

CoffeeScript classes are compiled into constructor functions that allow us to instantiate JavaScript objects. Using CoffeeScript classes makes use of best practices to define objects by keeping private variables private and making proper use of function prototypes.

In this section, we will look at defining classes with properties and methods, using class inheritance, and some of the hurdles we can run into when using CoffeeScript classes.

Defining classes

Creating a class involves using the class CoffeeScript keyword to define our class name, prototype properties and methods, as well as class variables and methods.

In this section, we will define a number of CoffeeScript class examples and see how they are used.

How to do it...

We can create a simple CoffeeScript...