Whenever I start a new application, the thought of writing the javascript from scratch – or even just relying on my own libraries I’ve built up during my time as a UI developer – seems cruel and unusual. These days there’s just no reason to not use one of the many available JS frameworks out there: Prototype, jQuery, Mootools, Ext JS, Dojo, YUI – to name just a few of the larger players. These libraries abstract away the never-ending cross-browser idiosyncrasies, provide you with some really extensive practical function libraries, and let you focus on actually implementing your ideas. What a novel idea. Thanks to these beauties, writing javascript is no longer the horror show that it used to be.
For some long-forgotten reason, when I first started exploring these frameworks I settled on Prototype and Scriptaculous. It was probably the beautiful Scriptaculous effects that sold me. Now, having used Prototype on a number of projects I thought it was about time I learned more about how it worked and what other gems lay within its core. The online Prototype API is an excellent resource – and very clearly written – but lacking any sort of search mechanism. For that reason, certain information can’t be found unless you know where to look for it. [Why is there no Array.contains() function? There's no mention of it in the Array section... Months later I stumble upon Enumerable - ahhhh...!]. The scriptaculous documentation, on the other hand, is god-awful. Navigating their site to find out the simplest thing can take hours of painful searching, clicking, cries for help, blaspheming – finally ending with you either giving up or relying on Google to save the day. Avoid their documentation at all costs.
So anyway, I picked up this book to fill the gaps of my knowledge, especially with regard to Scriptaculous. The reviews I came across were pretty positive, so I thought I’d give it a go.
The book was… well, a little disappointing, to my mind. It’s not a definitive resource, which the author makes perfectly clear. But certain basic things like available selectors for the $$ utility function are omitted with the disclaimer that “we don’t have space to provide a full tutorial on the types of selectors here…”. That bugged me: that’s why I GOT the book, so that All Things Prototype and Scriptaculous would be covered and explained. The $$ function is such a commonly used function, you’d expect it would be covered in depth… wouldn’t you?
But it’s not all bad. I very much enjoyed the chapter on functions, notably the discussion of bind() and bindAsEventListener(). It’s very clearly explained, and I think that closures and binding have finally found a permanent home in my slow-witted brain. The chapter on Prototype Objects wasn’t bad, too: it certainly helped with building my Smart Lists Prototype extension.
Perhaps my excitement over this framework has waned because I’ve been recently exploring another: jQuery. I turned to jQuery out of necessity, since I needed a JS framework that was compatible with Adobe AIR. In a recent post in the “Prototype: Core” Google group, Thomas Fuchs (the lead developer for Prototype) said there were no plans to support Adobe AIR since it “broke the specs”. True enough, but to my mind that’s not enough reason to not accommodate them (if we did this, no script would ever support IE). Other than forbidding eval(), I’m not sure how AIR deviates from the ECMA specification. I’d be curious to know.
Having played with jQuery for a week or so, I must admit I’ve definitely had more “wow!” moments than I did with Prototype. Prototype feels like it’s really geared towards developers, whereas jQuery feels like any bozo (even my retarded cat, “Fish”) could use it. That’s a good sign. I’m going to convert my Smart Lists app to jQuery just out of curiosity to compare the frameworks. Maybe I’ll post about the differences then.
Anyway, to get back on topic and conclude: despite the misgivings mentioned above, “Prototype and Scripaculous in Action” is a good book and well worth the read. Just don’t expect a definitive guide.
Recent Comments