'Secrets Of The Javascript Ninja' Review

Written by
Published on
Modified on

I "know" JavaScript, the way that a new college graduate "knows" every programming language ever made. When I first graduated from college I would have every language listed on my resume. I was a genius really. I took a 4 month class in the language after all, so how could I be anything but. That's how I know JavaScript.

I know which function to call when, but I don't know why. I can create a for loop that traverses an Array of objects and picks one out and copies a property, but I don't know how it works. And the more I program, the more I realize how little I really know. And to me that's one of the more frustrating things about being a developer. You sometimes spend so much time memorizing syntax that you forget how important learning is.

I decided to pick up "Secrets of the JavaScript Ninja" in order to sharpen up (no pun intended) my skills. This book has high reviews on Amazon and friends of mine have recommended it to me on numerous occasions.

This book is written by John Resig, the creator of the now infamous jQuery. Which is enough marketing for me. It's a 300+ page book and is meant for the more experienced JavaScript developer. You won't be learning for loops and if statements here. You'll be learning about function scopes and debugging practices and how and when to use the apply and call keywords. Basically the stuff that you don't normally need to think about when working with simple JavaScript projects.

Overall the book keeps a pretty good pace and covers very important topics that every serious JavaScript developer should know. It's definitely not for anyone new to JavaScript or new to programming in general. You don't need to be a seasoned developer to benefit, but knowing the basics of function structure, timing events, and debugging will help the process. Here's a few of the main topics that are covered in the book and that I personally found to be the most helpful and informative.

Debugging JavaScript

The book takes an interesting approach by introducing debugging and testing topics immediately from the start, which most textbooks that I've read usually reserve for the last few chapters. I actually like this approach. Normally with debugging saved for last, I end up ignoring those chapters. I get to the heart of the code, the syntax, and I probably finish the text at the 70% mark. By introducing testing and debugging first, the book sets up a nice framework for testing that will run through the rest of the chapters. Here you'll learn good ways to output content and how to work with test groups, which definitely do make an appearance once you get to chapter 3. The book also covers several testing frameworks and their best use case scenarios and offers several small snippets on how to debug asynchronous applications.

Personally for me this chapter was more informative than anything else as I currently have my own testing framework set up that seems to do the job alright. But it's definitely useful to see someone's approach to the whole thing and perhaps take a few elements for my own work while I'm at it.

A Deeper Look At Functions

Now we're getting somewhere. Chapter 3, and the rest of the book really, goes into the usually ignored intricacies of JavaScript functions, which do not act in the same fashion that they do in other languages with similar syntax. The book covers how they work and how to leverage the power of functions to get the desired result. For me this was a turning point in my JavaScript development. There was a slew of info that I wasn't aware of with how JavaScript treats functions internally. While I may have known about a few of these things, I wasn't 100% sure if it worked the way that I thought it worked. And this book offers concrete examples for everything that it covers.

Function context isn't something that I normally thought about, until now. I used functions mainly in the one way that I knew how to use functions, and that would be as such:

function func1()


Whenever you see a JavaScript being called, this is probably how you're going to see it. This is limiting however. Knowing how functions can be called in different contexts and how you yourself can specify the context opens up a huge world of possibilities in your code. And while these are simple concepts, they are usually concepts that are overlooked or ignored.

There are several areas that deal with recursive function calls, which I personally avoid at any and all cost. But that's a personal choice. While it can simplify the amount of code that you write, it's also a big harder to read I think and makes debugging slightly more difficult as well. But the examples in the book do a fine job of showing recursion in action.

Understanding Closures

On a recent project I was required to dynamically create elements on a page and at some later point grab the incremented value of that chunk being selected. So for example, you would click on "Add Region" and a set of controls would get drawn onto the page. Do this 4 times and you'd end up with 4 regions. When you click on a control in the second region you need specify that you want the 2nd regions control. Try it with traditional JavaScript and you won't get anywhere fast. After some Googling I found a StackOverflow page with a solution and mentions of JavaScript Closures. I pasted it and it worked. I had no idea how or why it worked, but it did and that was enough.

This book covers the importance of Closures and does so, once again, with full examples and comparisons. The examples build upon each other in a way that makes them easier to grasp. After months of just pasting in code from the interwebs, I can finally start to come up with that same code, and to me that's the end of goal of learning anything.

This Book Is Difficult

This is definitely not your "Learn Javascript in 4 easy steps book". The concepts are difficult and for many will probably be new. For me personally this book covers the topics that I've made sure to avoid for the past few years. And that definitely makes it a challenge, but a welcomed one at that. It spends a good bit of time on regular expressions and recursion and object oriented programming using prototype. But if you want to get to that level, the level at which you can create your own framework, like John Resig then you need to learn these core concepts.

Who Should Buy This Book

Overall this is a great book for anyone serious about really learning JavaScript. Within the first 50 pages you will get way more insight into how JavaScript runs internally and you'll be able to change the way you program. JavaScript is a functional programming language and it should be treated as such and Resig makes it a point to get that message across. The small code snippets spread across the chapters are short enough that you can type them in less than a minute and done so in a way that they build upon each other. Those debugging functions that you wrote in chapter 1? Yeap, they will be used in all of the future chapters as well. Even if you're a seasoned JavaScript developer, there will be something in this book that you didn't know before. If you're just using JavaScript to

Leave a comment

No messages posted yet

Developer Poll


Add a comment

Send me your weekly newsletter filled with awesome ideas