DailyJS

Prototype 1.7

Alex R. Young

Subscribe

@dailyjs

Facebook

Google+

frameworks prototype

Prototype 1.7

Posted by Alex R. Young on .
Featured

frameworks prototype

Prototype 1.7

Posted by Alex R. Young on .

Prototype 1.7 RC1
has been released, which introduces Sizzle for
the selector engine, Element#on,
Element.Layout, and bug fixes.

Sizzle

Sizzle has been on the cards for a long time, but it's actually becoming
a reality. Building Prototype with different selector engines is
possible, including the original, by using Rake:

rake dist SELECTOR_ENGINE=legacy_selector

Element#on

This is a shortcut for binding events:

$("messages").on('click', 'a.class_name', function(event, element) {
  // Your event code here
});

This removes a line of code from Prototype 1.6 style code where elements
are extracted from the event.

Element.Layout

Prototype now has a consolidated measurement API:

$('elementID').measure('width'); // Integer
$('elementID').measure('border-top');

Fixes

ES5 compliance forms a big part of the bug fixes. There are also
performance optimisations. The release is tagged as 1.7rc1 on GitHub,
with a summary of all the changes in the
CHANGELOG.

My Take

These changes are positive -- Element#on makes Prototype
code more concise, and measuring elements has always been slightly
clumsy so the new layout API might have positive repercussions,
particularly for animation and graphics libraries. Thomas Fuchs uses
Prototype for scriptaculous, so this might be a good thing for scripty2
which uses
Prototype
.

Finally switching to Sizzle is interesting because it's a widely adopted
and very focused library. There are enough selector engines out there,
so the open source community won't suffer by Prototype's engine becoming
legacy.

Remember that this means XPath selectors won't work. Prototype supported
XPath in browsers with document.evaluate, but Sizzle will
raise Syntax error, unrecognized expression:
//xpath/goes/here
.