O'Reilly logo

CoffeeScript Application Development by Ian Young

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

A new idiom: options objects

Now we're going to look at an idiom for passing options to a function. This isn't a new feature of CoffeeScript. Instead, it's a convention that makes use of several CoffeeScript features we've already learned, and uses them in a pattern that is easy to understand and useful in a wide variety of situations.

Tip

This idiom is also common in Ruby programs. Ruby makes extensive use of hashes (the equivalent of simple objects), and has loose syntax rules (much like CoffeeScript) allowing hashes to be passed to functions without extra noise. Other languages, such as Python, offer similar benefits via named arguments.

The idea is simple: a function accepts an options object, which may contain keys for any less-common or less-obvious ...

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