Object-Oriented JavaScript book review

March 11, 2009 – 7:14 pm Tags: ,

I was recently contacted by Packt Publishing, and asked if I wanted to review a book they published – Object-Oriented JavaScript, written by Stoyan Stefanov. I hadn’t reviewed books before, but I decided to give it a shot!

As stated on Packt’s website, by reading the book you will learn:

Create scalable, reusable high-quality JavaScript applications and libraries

  • Learn to think in JavaScript, the language of the web browser
  • Object-oriented programming made accessible and understandable to web developers
  • Do it yourself: experiment with examples that can be used in your own scripts
  • Write better, more maintainable JavaScript code

It also says:

After reading this book, you’ll be prepared to ace your JavaScript job interview and even impress with some bits that the interviewer maybe didn’t know. You should read this book if you want to be able to take your JavaScript skills to a new level of sophistication.

which would definitely be a benefit, don’t you think so?

Does the book deliver all this?

The contents

The book is divided into 8 chapters, four of which deal with the basic features of the JavaScript language, and the other four dive deeper into the language and the actual object-orientation parts like inheritance and design patterns.

The book uses Firebug as the main “development environment”, which I think is a good thing. Firebug is an important tool for a JavaScript programmer, and it works quite well for the task of teaching and learning too.

The book uses tip boxes, which contain best practices, common mistakes or other useful information, and the code samples in the book are consistent in style and display use of good practices.

Each chapter also contains exercises in the end, which help you to learn the concepts introduced in the chapter.

The JavaScript basics

The first chapter begins by looking a bit into what JavaScript is: Where it came from, where it is now and also a bit about the future. It serves as a nice look into the language’s roots. It also introduces JavaScript and OOP concepts, and compares them with other languages.

Next, in the second chapter, the book looks more into JavaScript’s types, expressions and constructs. Everything is explained thoroughly, and using language that even beginner programmers should understand. It even explains terminology for words like “operator” and “operand”, so even if you’re not familiar with these terms – for example if english isn’t your native language – you won’t have any problems with the upcoming chapters. It also explains more obscure syntax like the exponential “2e-5″ and special values NaN, Infinity and others.

The third chapter is all about JavaScript functions, again starting with basics, terminology and explaining things very thoroughly. It goes into more detail and more complex examples about functions too: anonymous functions, inner functions, etc.

As an added bonus, this chapter looks into some common JavaScript built in functions.

Chapter four introduces objects, which have been refered to a bit earlier in the book as well. As usual, it’s very clear and everything is explained well. It talks about how JavaScript’s object oriented features differ from other languages and provides some examples which are useful if you’re familiar with some “classical” OOP language. Like with the previous chapter, this one also shows you how to use built in JavaScript objects such as Number and Date.

More in-depth

The fifth chapter talks about the prototype property. You can read most of this chapter online here at my blog. There’s a bit more towards the end of the chapter which isn’t included in the post, though. This chapter is one of the most useful parts in the book for readers who are more experienced in JavaScript.

Chapter six is again a chapter looking deeper into JavaScript: inheritance. It explains various inheritance styles possible in JavaScript, such as prototype chaining and pseudo-classical inheritance. Also talks a bit about Yahoo! UI Framework and the Prototype library.

The seventh chapter is dedicated to the browser: The browser object model and the document object model. It covers cross browser compatible features of the BOM and DOM, like working with DOM nodes and using XMLHttpRequest. It also talks about the event model used in the browser, and some help on how to make things work in IE. It does not go into very great detail, but serves as a good primer to working with the browser’s features.

The final chapter looks into coding and design patterns. This one covers common things you see in modern JavaScript code, such as namespaces and initialization patterns. It also shows how to achieve public and private functions, and chaining, which is very common in jQuery. This chapter is very good, especially as many frameworks like Dojo and YUI use JavaScript in ways which can be confusing to beginners, but after reading this, you should understand them quite well.

Appendixes

The book also has four appendixes: A list of JavaScript reserved words, a list of builtin functions with examples, a list of objects with examples and a JavaScript regex syntax index.

Good things

The book is very thorough in explaining how JavaScript works. The first four chapters make the book suitable even for those who haven’t never used JavaScript before. They also contain some tidbits which more experienced programmers might not know about. The last four chapters make the book useful for people who are familiar with JS, and even those who are quite experienced in it can gain some new insights, for example about the prototype property or inheritance.

To highlight some good parts:

  • The first chapter shows a Firefox “strict” JavaScript parsing mode I did not know about
  • The third chapter explains “self executing function” syntax, (function(){ … })();, which used to confuse me a lot some years back
  • The chapters on prototypes, inheritance and patterns are excellent, and they had various small things I didn’t know about

Bad things

It’s difficult to find bad things about this book. Maybe the fact that I only have it as a PDF?

There were some small places for improvement, though. In the second chapter it might have been a good idea to mention that lazy evaluation in conditionals is also known as “short circuiting”.

Also, the third chapter code examples displaying inner and outer functions used f() and n() as the function names. It would probably have been a little better to use descriptive naming like outer() and inner(), so you wouldn’t have to look at the code example to see which one is which.

If you want to learn more about Ajax or DHTML-style tricks, this book may not be for you. While the browser environment chapter is good as an introduction, and you can definitely start using JavaScript on websites based on it, it doesn’t go into more advanced things.

The bottom line

To go back to the initial question, “does the book deliver?”, the answer is definitely yes. The book delivers all it promises, and after reading it, you will be able to impress interviewers.

All in all, the book is a great read for anyone who wants to learn JavaScript, or improve their existing skills in the language. The book is most useful for beginner to intermediate level JavaScripters, but may also contain some useful things if you’re more experienced.

Share this:
  1. 7 Responses to “Object-Oriented JavaScript book review”

  2. Thanks Jani, excellent review. Very good points re: bad things. I know I had something in mind with the f() and n() naming but cannot seem to remember now. f() must have been for “function”.

    Thanks very much for taking the time to review the book and I’m glad you liked it.

    By Stoyan on Mar 12, 2009

  3. Great review mate!

    I hope to get the book soon since you enjoyed it and I know you like your javascript :)

    By CodeJustin on May 3, 2009

  4. Hi Jani!

    I’m a developer at javabooks.org. We just went online two days ago, so we need lots of help with the reviews. We’ll be happy if you’d like to post your review on our web page too.

    Thanks,
    Mircea

    By Mircea on Sep 16, 2009

  5. This is not Object Oriented Javascript book. It’s just basic good JavaScript book. It’s missing some explanations who/why/where/what/how/etc/etc.
    Exercises at the end of the chapters are pointless for beginners/intermediates.

    Begginers will be lost, they will not have a clue what’s Object Oriented thing.

    The closest thing to Object Oriented thing is YUI and Mootools libraries.

    This book is good to read as an extra and do one-two line typing in firebug.

    The real books for Object Oriented Javascript is the following: (sorry there is no one miracle book:)

    1) Good Bad Parts (beginners should start with this one)
    2) Next This book: Object Oriented JavaScript
    3) Pro JavaScript Design Patterns

    4) YUI library tutorials (extend)
    5) Mootools tutorials (how to create/extend)
    6) jQuery extend tutorial(s)

    6) Inspect Author’s code: widgets (YUI) or plugins (mootools), jQuery plugins.

    7) Online material regarding some browser specific issues.

    8) High Performance Web Sites (Yslow)

    9) Even Faster Web Sites (it’s continuation of number 8)

    It’s a lot, but it’s fun.

    By M on Oct 6, 2009

  6. Thanks for pointing out some good resources, M. I agree with you that those are valuable reading for beginners. However, I disagree with jQuery: Many parts of it are really not worth reading – the code is very confusing, and especially in user-contributed plugins the conventions are often poor.

    By Jani Hartikainen on Oct 6, 2009

  1. 2 Trackback(s)

  2. Mar 17, 2009: links for 2009-03-17 « sySolution
  3. Oct 12, 2009: Going to review Zend Framework 1.8 Web Application Development | CodeUtopia - The blog of Jani Hartikainen

Post a Comment

You can use some HTML (a, em, strong, etc.). If you want to post code, use <pre lang="PHP">code here</pre> (you can replace PHP with the language you are posting)