Wednesday, November 7th, 2007

Prototype 1.6, 1.8 and The Book.

Category: Announcements, Book Reviews, Books, JavaScript, Prototype, Scriptaculous

This is a big day for Protoscript friends. The triple release. The big one. This post is a long one two as it discusses:

Prototype 1.6

They cleaned up, and 1.6 is a really nice piece of work. A lot of little nit-picks are now solved, and you are left with the lean mean machine that you know and love.


  • Ajax transport objects are now automatically wrapped in an Ajax.Response object.
  • Ajax.Response includes support for accessing JSON response bodies as JavaScript objects via the responseJSON property.
  • The class API now includes full support for inheritance and superclass method calls. (See Mislav’s tutorial for more info.)
  • Class objects now have an addMethods method for adding instance methods after creation.
  • Elements can be created easily with the new Element(...) syntax.
  • Element#insert provides a unified API to DOM element and HTML fragment insertion.
  • Element#select is an alias for getElementsBySelector and is now the preferred way to find elements by class name.
  • Element#wrap lets you easily wrap an element inside another element in place.
  • Enumerable methods on Array are now backed by native Array#forEach implementations when possible.
  • Enumerable now has aliases for equivalent JavaScript 1.6 Array methods, and support for JavaScript 1.6’s context parameter for automatic callback binding.
  • Enumerable#grep now calls the match method on its first argument, so you can use it to e.g. filter an array of DOM nodes by CSS selector.
  • Event objects are now automatically extended with instance methods, so you can write e.g. event.stop() instead of Event.stop(event).
  • Prototype’s event API now supports firing DOM-based custom events with Element#fire.
  • The new dom:loaded custom event fires when the entire document has loaded and is ready for manipulation.
  • Function#curry allows for partial application of function arguments.
  • Function#wrap facilitates simple aspect-oriented programming and provides the basis for Prototype’s superclass method call mechanism.
  • Function#delay delays invocation of the function by the given number of seconds.
  • Function#defer schedules the function to run as soon as the interpreter is idle.
  • The Hash API has changed, and you must now use Hash#get and Hash#set instead of directly accessing properties on Hash instances.
  • String#interpolate is a shortcut for instantiating a Template from the string and calling evaluate on it.
  • Object properties can now be used in template replacement strings. 1.8

This is the last release before 2.0 comes out and features:

  • Complete rewrite of Ajax.InPlaceEditor and Ajax.InPlaceCollectionEditor
  • Full CSS inheritance in Effect.Morph
  • New core effect: Effect.Tween
  • Sound: play mp3 files for sound effects; uses native playback on IE and available plugins whereever possible
  • Duration and distance options for Effect.Shake
  • Performance improvements
  • Tons of bugfixes

The Book (Reviewed by Stu Halloway)

The skinny: If you develop with Prototype and Scriptaculous, you need
this book.

Prototype and You Never Knew JavaScript Could Do This! is a long book, by Pragmatic Press standards. At first glance,
this might seem doubly odd, since the libraries themselves are quite
small, totaling only in the 100s of KB. But before I even opened the
book, I hoped that the length might be justified, for two reasons:

  1. Prototype and Scripty (hereafter P&S) are packed with dense,
    expressive, beautiful code, and they can do far more than their size
    might suggest.
  2. Along with several other Ajax libraries, P&S embody a modern
    JavaScript style that embraces functional programming. This new style
    is not well covered in the JavaScript books currently in print (as of
    November 2007), so to learn P&S you also have to learn to think about
    JavaScript in a new way.

Once inside the book, I was delighted to find that both of my hopes
were addressed. Porteneuve dives straight into the deep end,
embracing JavaScript’s functional style immediately in Chapter 2 and
never dumbing down the example code. (Don’t worry, there are forward
and backward references to help you along. This is especially nice if
you are reading the electronic copy of the book.) You may need to
read some sections of this book multiple times, and that is a good

The coverage of both Prototype and Scriptaculous is thorough. Of
course the marquee features receive due attention: Prototype’s
Ajax.Request and Scriptaculous’s Effects each have their own
chapters. More interesting to me is the thorough coverage of the less
visible parts:

  • Prototype’s functional capabilities are significantly enhanced for
    the 1.6 release. Chapter 4 shows how to use curry, bind (including
    multiple argument invocation), delay, and defer. You can even do some
    lightweight Aspect-Oriented Programming (AOP) with the new wrap method.
  • Chapter 7, “Playing with the DOM is Finally Fun”, nicely mixes
    tutorial and reference. The Staff Manager example motivates each
    section, but each individual section also acts as a reference for a
    set of DOM extensions.
  • The Event mechanism has been rewritten and enhanced for Prototype
    1.6. Chapter 6 covers the new unified event handling. Porteneuve
    motivates the event model by contrasting three approaches: the IE
    way, the standards way, and the Prototype way. With 1.6, portability
    improves again with synthetic events that fill gaps in the browser
    event model, e.g. dom:loaded. You can even fire and respond to your
    own custom events.
  • I have been using Scripty for years and I never even noticed the
    sound API (Chapter 20).

Of course, no reviewer feels complete until a few nits have been
picked. So here are a few:

  • Porteneuve embraces Prototype’s approach to JavaScript and the web
    (as do I). That said, there are many other approaches. It would be
    great to have an overview of the philosophical differences that set
    P&S apart from other JavaScript libraries.
  • The book’s style is casual, even by Prag standards.
  • Prototype and Scriptaculous are a rich buffet, and the book
    documents nearly every bite. Sometimes the book could be more
    opinionated about the menu. For example, I hate the $break feature in
    Prototype. Maybe Porteneuve does too–the example is certainly

These flaws are relatively minor. Overall I was impressed by the
amount of information in the book. I have been using P&S for years,
and I learned something new in almost every chapter.

For years, developers at software conferences have asked me “What is
the best way to learn Prototype and Scripty?” Until today, my answer
has always been “Read the source code.” Not any more. If you are
building applications with P&S, you need to read this book.

Posted by Dion Almaer at 3:22 pm

4 rating from 58 votes


Comments feed TrackBack URI

Rock on! Let’s all swallow our pride and make of Prototype the base for our custom tools, because there’s a need for normalizing JavaScript across browsers anyway, and it’s not easy to have several incompatible frameworks doing almost the same things everywhere.

For my part, I’ve started using it since a week ago and don’t plan to leave it anytime soon. :-)

Comment by Joao — November 7, 2007

Awesome post. …had the book for awhile as it’s been in BETA. All pragprog books I have read have been great, agree that this is no exception — great book. There is a wealth of documentation with Prototype far above any of the other libraries. It is my top choice for Ajax development because of the documentation, the community support, the support of Sam Stephenson, works nicely with jQuery, etc. (as an aside, writing code in Prototype is also a nice bridge towards programming in Ruby as a lot of the same style is employed in the prototype js lib)

Comment by Mark Holton — November 7, 2007

Congrats to the team and everyone involved. Writing apps has never been so much fun…

Comment by kangax — November 7, 2007

The Effect.Tween is really awesome. Yet it’s code size is small and one could think why it hasn’t been there already, while I was prototyping a cover flow like effect (known from Mac) I had exactly the very problem to solve: interpolate between two values in a given time frame. A few days later the beta of 1.8 was released and within 10 minutes I got everything running because the Effect.Tween was there. That’s just awesome!

Comment by Markus — November 7, 2007

kind of following similar steps from jQuery, but still, great jobs guys and congrats.
I think there were an earlier posts regarding how to choose the right framework. Every framework has it’s trade offs, and having a few of them to compare is much better than one leading solution.

Comment by Simon Jia — November 7, 2007

just curious, did Stu Halloway already finish reading the entire book?

Comment by Simon Jia — November 7, 2007

@Simon: pdf previews for reviewers have been available for a while.

Comment by Tobie Langel — November 7, 2007

Interesting. I’m looking for a javascript library myself, since ASP.NET Ajax is just not going anywhere. This looks good (documentation is a big plus) but if I wanted a comparison (not just file size, but in depth) of the major frameworks, where would I go?

Comment by Mike — November 8, 2007

John Resig (creator of jQuery) has an overview of the major JavaScript/ Ajax libraries here:

Comment by Mark Holton — November 8, 2007

Thanks Mark!

Comment by mike — November 8, 2007

We want protoculous updated, now! ;-)

Comment by David — November 12, 2007

@ Mark Thanx for the link

Comment by ghazii — May 18, 2008

That´s what i´m looking for…thanks!

Comment by Alexx — June 12, 2008

Leave a comment

You must be logged in to post a comment.