TLDR: If you want to understand how OOP works in JavaScript, read this book. It’s that simple. Read on if you want to hear me wax poetic, as this book certainly deserves the praise.
After Eloquent JavaScript rekindled my fascination with programming, dispelled my irrational fears of JS and dissolved my anger, I was still unsure about the way OOP worked with JavaScript. That’s not to say the author didn’t explain it: the topic is definitely covered, and I had some understanding of how it was supposed to work, but I still didn’t feel comfortable with it. I kept asking myself “Why can’t JavaScript just have classes like other languages?” My goal has been to be able to write professional-grade JavaScript, and I knew I couldn’t do that without using objects properly. I tried re-reading JavaScript: The Good Parts, but that didn’t really help. I was about to give up and put JavaScript on the shelf again when I got the press release for The Principles Of Object-Oriented JavaScript by Nicholas C. Zakas, in my inbox. The timing couldn’t have been better.
The best part of this book is that the author is able to pack so much useful information into 100 or so pages, without being cryptic. I was afraid when I got the review copy that I’d be dealing with “The Sutras of JS OOP”, a collection of JavaScript related aphorisms that would need to be unpacked by a guru in order to bring to light their true meaning. Luckily, Nicholas has mastered the art of being concise yet clear. I’d compare the book to a short and elegant function as opposed to a terse one-liner.
The Principles Of Object-Oriented JavaScript isn’t an introduction to JS, nor is it an intro to OOP. I wouldn’t recommend it if you’re just starting out with either, but you shouldn’t be scared to pick it up if you’re a JavaScript novice who’s read at least 1 other book on the topic. I’ve had years of programming-for-fun experience, and a couple of years of professional software engineering under my belt, but I lacked any real understanding of the way OOP worked in JavaScript, so this book suited me perfectly.
The book’s 6 chapters progress from an introduction of JavaScript’s types to a short discussion about popular patterns for working with objects. Each chapter builds on the material covered before it, and I’d recommend reading it in order, from cover to cover. There is enough sample code to demonstrate the concepts, and some helpful notes along the way as well. In some programming books the examples are so contrived that you lose sight of any real practical use of the features they’re intended to describe, but The Principles Of Object-Oriented JavaScript manages to avoid this for the most part. There are instances where a JS feature is explained and demonstrated with a sample followed by a warning to the reader to “not try this at home”, but I found those snippets to be more helpful than distracting.
Another reason I love this book is that somehow the author finds a way to pull back the curtain and let us peer into the world of JavaScript internals, without leaving us drowning in the deep end. He mentions internal methods that JavaScript calls when you work with objects, but is careful not to go off on what could be a very confusing tangent. It’s somehow just enough of a peek behind the scenes to whet your appetite to learn more about JavaScript and how it handles OOP. Of course the whole truth is that now I’m curious about what else the JS engine is doing when I’m not looking, but I’ve got to be careful or else I’ll lose sight of my goal which is to have no second thoughts about picking up a front-end heavy card off of my team’s story wall.
In closing, I highly recommend this book to anyone who is not quite sure of how object oriented programming is meant to be done using JavaScript. It’s my opinion that you couldn’t find a better book about the topic right now. It’s well written, concise, and packed full of great information. I’m going to read it again before letting anyone else have it 🙂