Pro JavaScript Techniques by John Resig

For a time now, I’ve wanted to read an advanced book about JavaScript, to perhaps fill in the blanks, and to get some inspiration and different perspective on how to implement various features.

Therefore, after some consideration, I picked up Pro JavaScript Techniques by John Resig.

John is the author behind jQuery, and has in that and other contexts shown to be a very knowledgeable JavaScript developer. Thus, it was with great anticipation I opened the book a couple of weeks ago and started reading. The first page actually start with some object-oriented code in the form of a constructor; if you’re a JavaScript junkie, just how cool is that?! πŸ™‚

A picture of the Pro JavaScript Techniques book cover

With such a beginning, I was having really high hopes for this book, but they were only somewhat met. The first chapter is a good introduction to modern JavaScript programming, but the second is, without a doubt, the best one in the book. It deals with object orientation, and more importantly, topics such as scope and closures. You won’t see that in many (if any) JavaScript books!

A fantastic read, and two great things brought up are the constructor property of a variable to see what type it is (more solid than typeof), and the call and apply methods. I’ve actually missed out on the latter methods, but they are superb for setting context for a function/event.

From there on, the book goes through unobtrusive JavaScript, where it deals with accessing the DOM, and after that, event handling is covered, and it points out the differences (and problems thereof) between the W3C event model and the IE event model. Vital information needed to write proper cross-browser and cross-platform scripts. This is followed by scripting with forms and then how to build an image gallery (not so sexy for me, per se, but I’m sure people are interested in the logic behind it).

John then explains AJAX in a good way, and then he presents three use cases:

  • Enhancing blogs with AJAX
  • Autocomplete search
  • An AJAX Wiki

I liked the one about auto-completing search, since it’s exactly what we see in all the fancy web-apps out there, while the other two were, frankly, kind of uninteresting. I would’ve preferred more “real” scenarios that web developers come across every day, than two cases, albeit technically challenging, who weren’t that interesting from a business and end user perspective. Maybe sometimes the use cases focuses too much on the goal, and not the way to get there.

I think I would’ve preferred him delving into the depths of jQuery; what obstacles he has come across, which interesting design decisions he has made etc. After all, I think the people reading this book are more prone (and hungry) to be creating their own libraries, as opposed to using existing ones. However, I guess some people would just see the book as jQuery pimping then, so I can understand why it is mentioned so sparsely.

The round-up covering the future of JavaScript and other cutting-edge technologies is very interesting, and the coming possibilities would almost make you drool (eh… or something). Always good to have something to look forward to!

Other people’s code

The book mentions and displays a fair amount of code from other people, where Douglas Crockford‘s and especially Dean Edwards‘ work is prominently featured. My stand on this swayed a little; sometimes I felt that maybe I instead should’ve read a book from one of those gentlemen, while at other times, I thought John did what was the right thing to do: showing and mentioning the best code out there.

In the end, though, I’m happy to see the best code and solution out there, no matter whose name is on it.

Verdict

I would say that any JavaScript web developer out there, from intermediate to advanced, can learn something sincerely valuable from this book. If you’ve just hooked on JavaScript, and want to be a scripting star, this is the book that explains how to learn about the inner workings of object-orientation in JavaScript, event handling and stretching the limits. With some more appealing use cases, this would be almost a perfect advanced book about JavaScript.

Pick it up, if you dare! πŸ™‚

 

Related reading

6 Comments

  • Funnily enough my copy arrived from Amazon this morning.

  • I guess I want to read Jack Slocum's JavaScript book, when and if he writes one. I just recently read his post about the jQuery response to his benchmarks comparing jQuery and the YUI-Ext library:

    http://www.jackslocum.com/blog/2007/01/12/domquer

  • Nate Klaiber says:

    My copy of this arrived last evening, and I had the same initial thoughts you did in that I thought it was great that the second paragraph began talking about Object Oriented JS. No frilly stuff from the beginning, this book dives right in.

    I am halfway through chapter 2, so I have a bit to go -but I really appreciated your review. I have been looking for some really good books on Javascript, without pushing a specific library. I think they could have separate books for the different libraries available, but I like keeping my libraries down to the tasks I need – without bloating the filesize. This is why I was hoping this book would dive more into JS, without pushing canned solutions or frameworks.

  • Jrf says:

    Interesting, will have to have a look at it some time.

    I can't help but swear by PKK and his quicksmode.org website – whenever I'm in doubt about anything to do with js, it's my first place of call.

  • Ash Searle says:

    Can you give a little more detail on how the book suggests to use the <code>constructor</code> property?

    I'd guess you always need a null-check for <code>null</code> and <code>undefined</code> values; and I'd expect <code>instanceof</code> may be better in some circumstances?

  • Robert Nyman says:

    Simon,

    Nice. I wish you a pleasant read!

    Daniel,

    Interesting, thanks for the link.

    Nate,

    I'm glad that you liked the review! πŸ™‚

    The book definitely isn't biased for any specific library, I can tell you that much.

    Jrf,

    Absolutely, PPK and his quirksmode is an invaluable resource.

    Ash,

    It is in situations where <code>typeof</code> would just return <code>"object"</code>, as opposed to <code>constructor</code> that would return <code>String</code> for a string and <code>Array</code> for an array.

    I'd say that it is basically used in the same way as <code>instanceof</code>.

Leave a Reply to Jrf Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.