Twitter: watching the Machinist, at least until i fall asleep
Subscribe via RSS or email  #7,120


Preview: Pro JavaScript Design Patterns

Jan 18, 2008 in ,

Several weeks ago I was approached by my friend Dustin Diaz, Google UI engineer extraordinaire, about a new book he co-authored that was recently published. I said I would take a look and post something about it to thank him answering my endless JavaScript questions for years. The book is entitled Pro JavaScript Design Patterns. I’ll be honest, that name sounds rather scary to me. My intellectual JavaScript acuity lies somewhere in between Cmd-C and Cmd-V if you catch my drift.

Apress - Pro JavaScript Design Patterns

I’ve always thought of JavaScript in a bad way, as an unnecessary programming language that usually added bulk to applications that could have received the same utility from server-side tactics. Obviously my logic has changed with the advent of RIAs where JavaScript code is a large component of an entire application. For example, Skribit’s widget uses the Appcelerator RIA platform to do more with less code, mostly JavaScript.

While I’m not within the target audience for Pro JS Design Patterns, my knowledge of server-side languages brings in some familiarity with what the book covers. It assumes you have a decent to moderate working knowledge of JavaScript to which you can apply various development techniques and implement design patterns. The overall result of structuring your code to abide by such design patterns revolves around maintainability (hugely important with larger applications) not to mention other nouns like speed and readability.

Pro JS Design Patterns covers (and I’m taking this straight from the TOC) OOP JS and the factory, bridge, composite, facade, adapter, decorator, flyweight, proxy, observer, command and chain of responsibility patterns. Leave a comment talking about anything JavaScript-related and how this book might help. I’ll send this book to the best comment.

No one has saved this post on del.icio.us. Why not bookmark it?



11 Comments

  1. oO0o… This book seems to hit just the spot for me. I’ve been learning js just a few months ago, coming from somewhat the same background as you did about js. But yea, i just started getting out of the cut n paste and starting to actually write stuff. Unforunatly Im kinda lost as far as “how to write” better oop in js and this book sounds like i could learn just that via js design patterns.

  2. This is a must needed knowledge for anyone planning on learning proper JavaScript.

    Support for OOP is horrible in JS (it wasn’t really designed for it), so books like these are important to learn how you can push JS to the limits and more importantly, do it right.

    This is a must have book on anyone’s shelf who takes JS seriously. Go get it.

    P.S. Don’t send me the book!

  3. I think it’s great that there is a book on how to write good Javascript code. For the most part, I believe that JS is seen as a language that you can just hobble together and cross your fingers with. It’s good to see that there is someone promoting a serious, professional view of Javascript and that it should be well maintained and structured like any other language.

  4. Javascript was once on my list of things to avoid. It actually is a wonderfully powerful language with a lot of excellent features and capabilities. It is simply the browser battle that can leave someone feeling raw.

    I’ve found that a huge part of writing maintainable Javascript is to lean on the frameworks that are available now. Aside from the countless widget libraries there are things like Prototype (my favorite) and JQuery that can pair nicely with any other well-behaved library and make writing JS in general significantly more pleasant.

    If you are writing Javascript heavily try out IDEA. It does an excellent job of indexing and wrapping smarts/inspections/tools around Javascript development. Combine that with the firebug extension for Firefox and you can feel like a legitimate software engineer while writing it.

  5. I’m mostly using script.aculo.us and prototype for my Ajax-needs. But there are certain things frameworks can’t do - that’s why i write my own javascript code.

    A few years ago i switched from coding “plain” PHP to using Symfony: MVC and design patterns rocked my world.

    Currently, my JavaScript is messed up and really needs some organisation - somehow my JavaScript Code reminds me of my PHP code 3 years ago.

    I hope that JavaScript Design Patterns will take me a huge step forward like Symfony did with my PHP code.

  6. @ Arthur - I know exactly what you mean. Once upon a time, I bragged to a friend how intelligently I had crafted a nested hive of tables, colspans, and rowspans into something IE6 friendly. How clever I felt…before he uppercut me with the Web Standards Project.

    That’s how I feel about my JS understanding (and to a slightly lesser extent PHP). My learning process usually goes something like:

    Find a script or widget (ex: JS Lightbox or variant)
    Dissect the code until flow makes sense
    Stuff sleeve with tricks (enough to remember what to Google next time)

    I’ve always wondered how often people refer to the “code” books that line their shelves.

  7. Prior to working as a full-time web developer, I didn’t think much of Javascript either. I focused mainly on the server side languages because it was what was necessary in getting my applications to spit out the data to the end-user.

    During my interview for my job, I was quite embarrassed to admit that I didn’t know Javascript. Like you mentioned, I usually referred to snippets of code found through googling, and quickly copied and pasted it into my projects. However, when you’re creating a custom application that has an objective that isn’t really common, it helps to know, and now I see the importance in this client-side language.

    While working on a recent project, I was encouraged to use the Yahoo YUI framework. With these javascript frameworks, it’s much easier to dip into javascript and create the interactivity internet users expect now that they’ve been spoiled by the likes of applications that widely used (I’m looking at you Google).

    I’m curious to read how OOP can be applied to javascript though. Like Dimitry said, it doesn’t seem like this language was intended for it.

  8. I take JS seriously. Look at AppJet. It’s a platform for building web apps entirely out of JS.

  9. Honestly, this book (like most books on design patterns) is going to tell you that your current coding methods are not the best… and that’s a good thing.

    Most of us cut, paste, and cannibalize code from whenever we can. What is missed in this theft is the initial structure, designing, and planning. If you have ever taken a step back from your js and noticed that it is impossible to understand, a design patterns book is for you.

    Going through the process of exploring design practices will create better programming practices.

    Many methods exist for doing anything… especially in js. However, a book like this will teach what the common, essential, and most efficient ways are.

    Most importantly, using design practices will help the programmer to adopt the common vocabulary that is required for collaboration. From JSON to AJAX, from Facebook to OpenSocial– javascript is an essential tool. Following established design practices will allow the programmer to work with the natural flow of previously established services.

    Learning good design practices is essential for transitioning from javascript cannibal to true javascript coding guru.

    Design practices are nothing more but learning how the experts have done it successfully before you.

  10. Thats for the advices, I liked Appcelerator a lot, think I will use it in my next projects! =)

  11. I’ve been using JS for a few years off and on and would love to get my hands on a great piece of literature like this. I am currently in my final semester at South Dakota State University and am in my second semester of senior design…

    Why am I bringing this up? Well… I’m making a Computerized Beverage Mixing System (similar to a bar monkey as seen at barmonkey.net) and my UI is done in PHP and Javascript. I am using the javascript to dynamically draw the image of your specified drink and it makes it proportional! This is done by drawing ellipses and stacking them on each other (changing colors whenever a new liquid is started). The live implementation of the prototype can be seen at lab.derekfernholz.com/SCABMS/scabms.php

    My next big task is making that image dynamically changeable in the customize drink page without reloading the page or having to redraw then entire image and I am lacking in a solid resource for Javascript.

    Thanks for your consideration!

Post a comment, receive Stammy points.


Send a trackback.


  • If you plan on posting code, run it through Postable first.
Copyright © 2005 - 2008 PaulStamatiou.com  Privacy Policy - Terms of Service Can't spell my name? Use PSTAM.com. Go back up ↑.