Chapter 7. Style and semantics
This chapter covers
- Rest and spread parameters
- Destructuring assignment
- Dealing with types
- Effective comprehensions
- Fluent interfaces
- Nuances of significant whitespace
In chapter 2 you took a highway drive through the CoffeeScript syntactic landscape. CoffeeScript is a small language, so the drive didn’t take you very long. That said, chapter 2 was deliberately fast-paced, and at the speed you were going, some details were necessarily postponed for later. Well, later has arrived.
To understand the full breadth of CoffeeScript programs you’ll find in the wild, you need to appreciate some subtler syntactic and semantic aspects of the language that require a bit more care and attention to grasp. These aspects—covered in this chapter—are spread and rest parameters, destructuring assignment, semantic issues around types and dealing with null values, effective use of comprehensions, fluent interfaces, and finally the nuances of dealing with significant indentation. First up, rest and spread parameters.
Imagine you’re displaying a table of teams in a competition ordered by the number of points they have (figure 7.1). When a team moves up in the rankings, you highlight the row containing that team.
Suppose you already have a highlight function that takes a name, finds it, and highlights it by invoking color and find functions that have been implemented elsewhere: