Iterating over Collections

I’ll be honest: I don’t like loops. Nine times out of ten, if I want to perform an operation on each item in a collection, I’m going to use one of the methods provided by a library like Underscore.js,[32] which allows the intent of the loop to be expressed more clearly than native syntax would allow.

Still, it’s important as a programmer to understand the language capabilities available to you. These are, after all, the fundamental building blocks that libraries such as Underscore rely on, and there are situations where you’ll want to put those building blocks together in novel ways. In this section, we’ll see how CoffeeScript allows you to write powerful, succinct loops without invoking a utility function.

Loop Syntaxes ...

Get CoffeeScript, 2nd Edition 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.