O'Reilly logo

Programming in CoffeeScript by Mark Bates

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

6. Classes

Classes1 are essentially a blueprint for creating new instances of an object with predefined functions and variables. These instances can then store state related to that individual instance. Over the years, JavaScript has constantly come under attack for its lack of any real support for classes.

In Chapter 5, “Collections and Iterations,” we looked at objects in JavaScript. In each example we hand rolled a brand new object and gave that new object a set of functions and values. This works great for the occasional simple object, but what if we wanted to have a more complex data model? More importantly, what if we wanted to have more than one of those complex data models? That is typically where classes come in.

Fortunately, CoffeeScript ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required