Book Review: JavaScript Phrasebook

JavaScript Phrasebook

JavaScript Phrasebook
By Christian Wenz
Sams Publishing

$14.99

Pocket books have a certain appeal: If you’re traveling abroad, you can slip a phrasebook into your back pocket while trekking through a remote village. Then, quick as quick as a flash you can be flipping through it searching for the perfect phrase with which to ask a local for directions to the nearest art museum (for example).

Being pocket-size is one thing, but there’s also something compelling about the “quick fix” phrase translator. Saves having to learn an entire foreign language after all, when all you really want to do is say something approximating “My cat is stuck down a well, please send help.”

When you’re programming or doing web development, the “quick fix” can be just as compelling. Sometimes it’s exactly what you need: having identified a problem, e.g. “I need to download a remote library”, to be able to flip through a programming “phrasebook” and find exactly the code snippet, or a near approximation, to do what you need. It explains the popularity of the Java Developer’s Almanac (which could be thought of as a catalog of Java code snippets).

The subject of this review – the JavaScript Phrasebook – has a similar approach, but as the name suggests, its author Christian Wenz has taken the “phrasebook” metaphor literally, and produced an excellent pocket-book packed with JavaScript code snippets, or “phrases”, for all sorts of useful tasks. It's surprising how much information the author has managed to pack into such a small space.

The book starts with JavaScript basics: using external JS files, dynamically loading JS files, using event handlers etc; then it covers the more commonly needed phrases such as detecting the browser type, preventing caching, and reloading the page. Later, the book ranges into form-related phrases such as disabling form elements and validating selection lists.

But the book goes beyond just “monkey-see-monkey-do” code snippets, as it’s also instructional. Accompanying each phrase, there’s a half-page or so of text explaining the theory. It’s a good halfway-house between theory and pragmatism.

For example, say you need to access individual rules within a style sheet. The CSS chapter provides the perfect “phrase” for the job, but also explains how the behavior differs between browsers, and provides a couple of examples to illustrate the differences.

The result is a book that’s more than just skin-deep, i.e. you won’t just find the perfect code snippet to type in and solve the current problem... you’ll actually learn something new at the same time.

About the Author

Matt Stephens is a senior architect, programmer and project leader based in Central London. He co-wrote Agile Development with ICONIX Process, Extreme Programming Refactored, and Use Case Driven Object Modeling with UML - Theory and Practice.