Secrets of the JavaScript Ninja |
Author: John Resig & Bear Bibeault Many think that JavaScript couldn't punch its way out of a paper bag? Is this just because they don't understand it?
There is no doubt that if anyone deserves to be called a JavaScript Ninja it's John Resig, one of this book,s authors and creator of jQuery among other things. There is, however, some doubt as to what being a Ninja programmer actually means - is it all fancy footwork with no method and science?
In JavaScript's case the situation is complicated because many programmers who think they have mastered the language haven't even scratched the surface. JavaScript is not Java, nor it is C++, nor is it like any of the other mainstream languages. It is an object-oriented, dynamic, functional language, and this means you will probably have to learn new things to get the best from it. This book isn't for the complete beginner and it isn't a coherent course introducing JavaScript even to a programmer. What it is is a set of looks at how JavaScript is different, so before you read this you need to have a reasonable grasp of JavaScript as a conventional language and want to know more.
The first part of the book sort of works its way around the main topics without actually coming to grips with them. We consider libraries, cross browser issues, testing and something about qUnit. Part 2 is where the book really gets started on its main core material. It considers functions simple and sophisticated. From basic functions it moves on to anonymous functions, recursion, functions as objects, variable length argument lists and so on. Next we look at closures, not just the basic idea but what they can be used for. Finally we reach the idea of the constructor and the complicated topic of the prototype. This part of the book ends with two chapters on practical matters but which are not really core JavaScript - regular expressions and timers. if you thought you understood timers, or if you know you don't, then reading this account should put you straight. Part 3 of the book is called Ninja Training and it is supposed to be about using the advanced ideas. It covers code evaluation, i.e. modifying code at runtime. We also learn about the with statement, which is a strange topic because it is not allowed in strict JavaScript. The section ends with a look at cross browser issues and problems with working with the DOM's attributes and properties. Part 4, "Master Training", covers events, the DOM and CSS selector engines. It isn't really clear why this is a separate section as the topics seem on a par with those included in Part 3. The approach taken throughout the book is a mixture of easy to follow explanation and less easy to follow examples. The examples generally show you something and then asks you what you expect to happen. Then it tells you the actual outcome and tries to make the general behaviour clear. This worked better when the general behavior was described in before the example. That is it is generally better to describe the principle and then present an example that illustrates it rather than the other way round. Finally, the structure of the book leaves a lot to be desired. There isn't much progression of topics and a critic of JavaScript could well level the complaint that the book simply demonstrates that there are no general principles behind the language. This isn't true, it is just that the authors prefer to explain loosely connected topics rather than present a modern coherent approach to the entire language and its most common runtime environment, i.e. the browser. This might seem like a harsh criticism, but to be fair this isn't what the book sets out to do. It really is a collection of readings about the more interesting parts of JavaScript. I guess an alternative title for the book could have been "JavaScript - the interesting parts". Despite all my criticisms it is important to note that this is a really enjoyable book if you know enough JavaScript and are enthusiastic to learn more. It really is a lot of fun and it could well make readers rethink their attitude to JavaScript and how they use it. As long as you are not a JavaScript beginner or a JavaScript denier, this book comes highly recommended. Don't worry about my few minor niggles, I'm nitpicking, buy a copy.
|
|||
Last Updated ( Tuesday, 19 February 2013 ) |