Prototype 1.6, Script.aculo.us 1.8 and The Book.

Written by on November 7th, 2007 in Ajax News.

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.

Highlights

  • 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.

Script.aculo.us 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 (by Stu Halloway)

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

Prototype and script.aculo.us: 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
thing.

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
    contrived.

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.

Source: Ajaxian
Original Article: http://feeds.feedburner.com/~r/ajaxian/~3/181258843/prototype-16-scriptaculous-18-and-the-book

Leave a Reply

You must be logged in to post a comment.



Site Navigation