Review: “Scope and Closures” by Kyle Simpson, O’Reilly Media

Cover of Scopes and ClosuresThis approaches my idea of perfection in a technical book. Simpson takes a limited and important part of JavaScript (scopes and closures, obviously) and explains it, briskly, and thoroughly, with simple code samples demonstrating how these language features work and how a working developer can employ knowledge of them to improve their work.

Like many long-time web developers, I learned JavaScript by picking up pieces here and there as necessary to get something specific done – very different from how I learned, say, PHP or Java. That “Brute Force and Ignorance” (BF&I, I call it) approach to JS began failing in the last few years as JavaScript changed from being an accessory to being a core component of a modern website, and I began a more systematic study of the language.

Simpson’s book is a very welcome addition to my effort. The book is short, covers its subject clearly and comprehensively, the style is good-natured with an insistence of getting things right, and uses examples simple enough that you don’t need to tap out code to get the point. If you’re already fairly experienced with the language you can read this in bed. It was a pleasure to read and a cinch to understand. Here’s a sample: “Closure is when a function can remember and access its lexical scope even when it’s invoked outside its lexical scope.”

I recommend this very highly for intermediate-level JavaScript users who want to improve the command of the language.

Native JavaScript for jQuery Methods

I like jQuery and rarely do a Web project of any size without using it. But always nibbling at me, only a little and usually in the background, is the fact that it’s big and it slows things down, so before typing in the <script> tag  I try to ask myself if  that whole big library needs to be loaded.

Most of the time it does need to be loaded, for lots of good reasons, but sometimes the only reason is pure laziness — the project would be better with a little native JavaScript rather than a big library, but I’d have to think a little bit harder for a few minutes.

Craig Buckler makes that few minutes of thinking a little easier with an article at SitePoint, “Native JavaScript Equivalents of jQuery Methods: the DOM and Forms“. The title doesn’t need any clarification — the article is well-written and carefully thought-out.

“The Modern Web” by Peter Gasston; No Starch Press

As the pace of change in the Web domain keeps accelerating, working Web developers, all of us but especially freelancers, struggle with finding the time to: 1) work; and 2) not get too far behind the technology curve.

This book was written to help with that struggle:

[T]his book is a snapshot of current, new, and near-future features in HTML, CSS, JavaScript, and related technologies, with a bias toward those that are best for building sites in the multi-device world.

The book begins by describing stuff that’s in a fairly advanced state of deployment, for example, elements introduced in HTML5 and WAI-ARIA properties, then moves through the spectrum to things not quite loose in the wild yet, like Web Components and CSS Variables. The author assumes some proficiency with Web technologies, sparing the busy reader long introductory explanations.

You will get a lot out of this book — in fact, I think you will get the most out of it — by first reading it through without concerning yourself too much with the plentiful code samples and implementation details. You’re unlikely to encounter a more articulate and engaging mid-level overview of the future of the Web platform anywhere, and the opportunity to gain a sense of how it all meshes by a quick read-through should be seized. You can re-read what is most timely for your current project, and then follow the links to further reading for more detailed and up-to-date information.

There is a good bibliography and suggestions for further reading appended to each chapter, and the references are gathered together again near the end of the book.

I found a lot in this book that I knew about, and more that I had never heard of, and came away with some confidence that I know where the technology is heading. I highly recommend this book for working Web developers.

The Modern Web
Peter Gasston
ISBN: 9781593274887
Publisher: No Starch Press
Released: April 2013
Pages: 264

JavaScript Testing With Jasmine by Evan Hahn; O’Reilly Media

You should know right away: this book is short, 41 pages, stem to stern.

Jasmine is a free-and-open-source JavaScript testing application developed by Pivotal Labs and available on GitHub.

After some brief why-you-should-do-this throat-clearing, Hahn walks the reader through the development of a few simple JavaScript functions and the Jasmine “suites” for testing them. He starts from the very beginning, getting and installing the software and setting up the environment. He explains every line of code and describes additional features and options of the application along the way and includes very clear instructions for writing and running the test code.

With no experience testing JavaScript and only a little experience writing any software tests, this book was exactly the jump-start I needed. I duplicated the sample code in my IDE, goofed around with it a little bit, breaking it and extending it to see what happened and then was quickly able to start unit tests in my current project. Not well, at first, but with some confidence that I’d be able to figure things out.

The prose can get clunky. Not unclear or incoherent, just lacking in grace, and there is one serious code error, already noted in the errata page for the book at O’Reilly Media. Hahn makes no mention of the active community of developers using and extending Jasmine nor of Jasmine’s shortcomings (it’s not good at testing DOM manipulations without an additional plugin) – this is very much “How To Get Started With Jasmine”.

Minus “why you should test your software” arguments and some enthusiastic coverage of CoffeeScript and Ruby, you’re left with something roughly equivalent to a high-quality Web tutorial. That’s nothing to sneeze at, but it’s not “The Definitive Guide”, either.