review: Functional JavaScript

Just like it says on the tin, Functional JavaScript (Michael Fogus[1]; O’Reilly, 2013) is just that: a book about writing JavaScript in a functional style with Underscore.js as the foundational library to give you some of the higher-order functions you need to get started.[2]

First, a disclosure: I have a very personal relationship with this book. Fogus is an old friend, and when he asked if I would help review it, I jumped at the chance. “JavaScript? Functional programming?” If the book was dipped in chocolate and came with a snifter of rye, it couldn’t be any more of my favorite things. And in this way, I had the privilege of reading some early drafts and watching it take shape.

What Fogus has written here is an outstanding introduction to functional programming as a style/paradigm, but he has also written what I consider to be the authoritative text on applying that style to JavaScript. He takes many of the sophisticated[3] functional concepts (e.g., pipelines, currying and partial application, protocols/mixins, immutability) and demonstrates how to set them up using nothing more than a little Underscore and JavaScript’s basic building blocks. It’s a real treat to watch him take these concepts which may seem academic or obtuse at times, and apply them with great effect in JavaScript. And it’s particularly amazing to see him take something that might otherwise seem impossible (I’m looking at you, trampolines) and then make it look almost trivial to implement.

Just like Underscore, Fogus’ book is surprisingly-small-yet-surprisingly-powerful. It shouldn’t be your first book on JavaScript,[4] but if you’re already comfortable (or at least “serviceable”) with the language, then this is the best route into programming JavaScript in a functional way. And why not put this all together? Seriously: JavaScript is the lingua franca of the web — it’s everywhere! — and as we do more powerful things in the browser, we’re going to need more powerful programming paradigms. Functional JavaScript lights the way.

And as an added bonus: you get Fogus’ awesome sense of humor sprinkled in there, making it a very fun book as well as very informative.

Disclosure: I received an electronic copy of this book from the publisher in exchange for writing this review. I was also involved in the reviewing/editing process. I’m also old friends with the author.

Sophisticated to the uninitiated; properly applied, these patterns lead to delightfully simple code. After you’re done with this book, I doubt you’ll think of them as “complicated”. (Though you’ll still relish in calling them “sophisticated”.) [↩]

Buy my book!

Beginning with the basics of PhantomJS, this book will dive into its core modules and guide you through how to solve real-world testing problems. This book explores a variety of test automation tasks, including executing JavaScript unit tests with the Jasmine, QUnit, and Mocha frameworks; functional tests with tools such as Selenium, Capybara, and CasperJS; performance analysis with tools such as YSlow; and much more.