Check out my
new book!
HTML5 Games book
Book review: Object-Oriented JavaScript
The good people at Packt Publishing were kind enough to provide me with a copy of the book Object-Oriented JavaScript by Stoyan Stefanov and it's just been sitting on my desk for far too long before I finally got around to reading it. But I did and so here are my thoughts on this book.

What's inside

Weighing in at just under 300 pages (excluding appendices) in 8 chapters, the book promises to teach you everything from the very basics of JavaScript programming to more advanced object-oriented patterns, regardless of your previous experience with programming and JavaScript.

When it comes to layout and ease of reading, I can't really put a finger on anything. In the very beginning of the book, various typographic conventions and such used throughout the book are explained but there shouldn't be room for much misunderstanding even if you skip that part. The pages read easily and have a nice balance of text and whitespace. Code examples, of which there are plenty although usually very short, are all clear, concise and easily identified.

The book takes a rather hands-on approach to learning and you're encouraged to try out short code examples as you read them. It works nicely, I think, at least if you're using Firebug (which the author suggests you do and also instructs you how to set up) since the book shows you both what you should type as well as the expected response from the Firebug console.

JavaScript basics

The book is more or less divided in two parts, with the first part (consisting of the first 4 chapters) dealing with general, basic JavaScript programming and the second part taking on the object-oriented aspects as well as dealing with the browser environment and discussing some design patterns.

And the first chapters do really start with the very basics. After a short introduction to the language in chapter 1, including its history as well as how it fits in among other languages, you're taken through the basic syntax of the language, the available operators and the primitive data types. It then naturally progresses to discuss functions and objects, including scope, the important topic of closures and how everything in JavaScript is an object.

Prototypes, the browser and patterns

Now, part 2 is where it gets more interesting. Chapters 5 and 6 explain in great detail how JavaScript is a prototypical language and shows with many examples how to write object-oriented JavaScript using constructor functions and prototype chaining. It's my understanding that many people new to JavaScript have problems grasping this part and the two chapters seem appropriately thorough with many examples and even a few diagrams when necessary.

I won't say much about chapter 7. It simply walks you through the objects and functions available when running JavaScript in the browser, ie. the document and browser object models (DOM and BOM). It's not the most interesting chapter seen in the context of learning the language but for those wanting to use it for developing web sites/apps, it's a nice and quick introduction if you don't have a book dedicated to that.

Chapter 8 finishes the "meat" of the book with a discussion of various common coding and design patterns, ranging from namespacing to JSON and singletons. They are all good topics but some of them get so little space that they seem more like appetizers for further study than anything else. That said, it's a good chapter and highlights how the language features you've just learned can and are being used to build real applications.

Near the end you'll find a few obligatory appendices listing things like reserved words, built-in objects and regular expressions. They are nice and detailed and about what you'd expect from a book like this, nothing more, nothing less.

A few comments

As mentioned earlier, it's suggested that you use Firebug while reading the book, but I suppose any JavaScript console could work and it's only meant as a tool to give you instant feedback. For the most part, the book deals with JavaScript in a strict language-only way, ie. it doesn't care if you're using JavaScript in the browser, on the server or in more exotic places. In fact, I was a bit surprised to see that, given this environment-agnostic approach, the author still chose to devote all of chapter 7 to the browser environment (DOM, BOM, etc). Not that it's bad or useless information (and it's certainly a good start), but you might want to look at other books for a more thorough introduction to client-side web development.

On the other hand, there are some areas that perhaps could've used some more space. Eg. things like public/privileged/private methods and properties in the context of JavaScript objects are only mentioned briefly in chapter 8 and a few of the other patterns discussed there could easily be "upgraded" and given a few more paragraphs.

You also won't find much about the newest editions of JavaScript, perhaps due to the book being, after all, somewhat tied to the browser environment where the newest versions are far from ubiquitous. As such, the book doesn't deal with the features introduced in JavaScript 1.6 and newer.

I'd say the ideal reader for this book is one with at least a bit of programming experience. While the first chapters are very basic (more experienced programmers might want to just skim these) the later topics do get more advanced and if this is your very first experience with programming, some of it could provide a challenge.


To summarize, I think this is a great book for learning the JavaScript language. It could perhaps have been a bit heavier on the OO side of things and maybe let some of the browser stuff go, but for a good all-round book on modern JavaScript this is a good bet, whether you're looking to taking your JavaScript skills to the next level or adding another language to your resumé. Depending on what you'll be using JavaScript for, you might also want to supplement with some material about all the good stuff in version 1.7 and/or DOM scripting.

If you want to get a taste of the book, there's a sample chapter available here in PDF format. It's chapter 2 which mostly talks about basic stuff like primitive data types, arrays and loops.

Finally, you can get the book here: (or
- or directly from Packt Publishing.
⇓ 9 comments yosh64

Thanks, I just quickly read the sample chapter and ended up buying the eBook. Usually I do more research before buying such things, but it seemed very well written, so hopefully it was worth while :).

August 15, 2009 at 8:41 PM

Plus I was eager to learn about things properly, it gets a little tiring looking through websites and ya end up wondering if what's said is the best way to go about things or whatever. Ohh, and ya learn about the handful of little things that might not get mentioned on websites and such, so I dunno.

August 15, 2009 at 8:46 PM

Just one thing I noticed in the sample chapter (chapter 2) where it makes you aware of the flaws involved in the quick approach to checking if a variable exists, that being "if (somevar) { /* do whatever */ }", such that any variable that evaluates to false will be treated as undefined. Anyhow they recommended doing as follows... "if (typeof somevar !== "undefined") { /* do whatever */ }", but why not just do "if (somevar !== undefined) { /* do whatever */ }"??? I just put a little script together (have yet to try a JavaScript console) to try in Google Chrome, and this works fine. So why would they not mention this? Anyhow I guess it seems pretty obvious, but I dunno.

August 15, 2009 at 10:30 PM

Also, just realised Google Chrome has it's own JavaScript console and such :), I guess Firebug is part of Firefox. Anyhows sorry for all the comments :).

August 15, 2009 at 10:59 PM

Yeah, the JavaScript console in Google Chome is pretty awesome. It fails kinda though when you have more than one JavaScript error at the time, but, it's very nice for quickly looking over your whole document and it's JavaScript.

August 17, 2009 at 10:41 AM
Simon F

I've never read a JavaScript book so based on this review I decided to get this one. I hope it's good :D

September 1, 2009 at 5:50 AM
cartouche d encre

We are working on C++ and my boss just got a new project on Java. So, our team have to learn JavaScript now. Thank you so much for giving suggestion to use the book, "Object-Oriented JavaScript". I will surely refer it and will definitely post it's review here.

October 5, 2009 at 11:07 PM
vitamine h

I m working with PHP and recently i got a project which needs some javascript functions.So i was searching for some good book of javascript and from your post i think this is the best book to learn javascript.Thanks for the information.

December 12, 2009 at 1:37 AM
australia photographer

I also Software developer and your book is nice and also good for Java script.It is easy and nice example.

December 21, 2010 at 8:31 PM
Post a Comment