DOM scripting review
All righty. I’m very lazy lately. I read less and less. However, if a book pulls me in, I’m well prepared to discard all the other forms of relaxation and swallow it all at once. Yes, this was the case with the DOM scripting.
What’s so great about it? First off, the book is not boring programming reference listing mambo-jumbo or whatever… It tells a story. What is the Designing with web standards (by Zeldman) for CSS, that is the DOM scripting for DOM/JavaScript.
What you won’t find
You will not find the JavaScript reference.
What you will find?
You will find defensive, unobtrusive and fully working examples of the JavaScript code, together with the explanations which facilitate understanding. If you’re just searching for a set of typical code snippets, Jeremy Keith, the author, is so generous that he gives it to you. You don’t even have to buy the book for it – most of the scripts are available online. (Ed’s remark: If you’re only interested in getting those, just take it away. But please, don’t come back crying for a job later this year.).
However, the greatness of the book is not in JavaScript functions provided, it’s in the clear and simple prose which will encourage you to consider behavior layer for what it really should be – the final touch for a web site, which can make a difference.
If you’re a designer, you are going to get some kinky new ideas about how to improve usability, interaction and overall look and feel on your web sites. If you’re a developer – you will learn how to write leaner, bulletproof JavaScript for manipulating DOM structures. What’s the most important, in both cases – you will learn about the importance of the process: structure first, presentation second and last but not least – the behavior.

8 Comments
Good Zeldman analogy. I agree, go buy this book.
Comment (#) by Nathan Smith — 29th January 2006.
I didn’t like the code in this book too much, but the lessons learned were excellent. Nobody has more clearly explained what unobtrusive Javascript is and why it is a good thing.
Comment (#) by Justin Perkins — 30th January 2006.
Justin, what about the code you didn’t like exactly? The style or something else? I’m just curious…
Comment (#) by marko — 30th January 2006.
I have a big hang-up about using multiple exit statements (returns) inside functions. That’s my biggest complaint, although there are others.
Jeremy argues that they (mutlitple exit points) aren’t exactly a bad thing in the book, but I find it difficult to see his logic.
Comment (#) by Justin Perkins — 30th January 2006.
I agree about the multiple exits, but he also explains a difference between traditional conventions and this approach.
I feel that, from the point of a JavaScript newbie, this way is much more readable and understandable, even though, you’re right – that shouldn’t be common practice and can eventually result in bad programming habits.
Comment (#) by marko — 30th January 2006.
Sure he does explain his reasoning, by saying (I’m paraphrasing) “Multiple exits should not be used unless they are at the top of the function". Then later in the book he goes on to say “Multiple exits should be used at the top of the function, except when they need to be somewhere else, like the middle of the function".
I’m sorry, but that is just poor practices to recommend to anybody, especially a newbie to Javascript. This only perpetuates the problem.
I don’t mean to hijack this post and I considered not posting this comment. I could probably go on and on, but I’ll stop here :)
Comment (#) by Justin Perkins — 30th January 2006.
Never mind the ‘hijack’, thanks for your remark.
Comment (#) by marko — 30th January 2006.
Marko, Justin,
There is balance and compromise in everything. When we are looking at web applications the key is performance. The more complex the code, additional flag comparisons, etc., the longer it will take to download and, later, execute. Having programmed at the operating system level, I can’t count the number of times I pushed return instructions onto the stack then executed them just to save nanoseconds here and there.
Certainly, it’s a stretch jumping from operating system code to DOM Scripting code but there is definite commonality, i.e., efficiency of execution.
In terms of style and best practices, I agree with you re: multiple exits. In terms of efficiency, IMHO, one must selectively bend the “style and best practices” paridigm, as appropriate.
I own a copy of Jeremy’s book and am working feverishly to master the concepts. Hopefully, one day, I will be able to create web sites as impressive as Jeremy’s personal web site, adactio.com.
Comment (#) by Gregory McCoy — 13th February 2006.
Sorry, the comment form is closed at this time, but if you have anything to say, please send me a message.