Chapter 4. Dynamic objects

This chapter covers

  • Objects as data
  • Object comprehensions
  • An introduction to prototypes
  • An introduction to classes

JavaScript objects are simple and powerful, but because they don’t work quite like objects in other popular programming languages, they’re often wrongly perceived as confusing and underpowered. With simplified and familiar syntax, CoffeeScript both eliminates the confusion and better exposes the inherent power of objects. Before diving in, though, what exactly is an object?

Objects are collections of named properties where each name maps to a value. The value of a property can be any valid CoffeeScript value. You write an empty object with a set of curly braces:

{}

That is an object, in literal ...

Get CoffeeScript in Action now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.