Friday, March 10th, 2006

Prototype Gets Some Serious Syntactic Sugar

Category: Programming, Prototype

According to this post on, everyone’s favorite Javascript library, prototype, has gotten some new “syntactic sugar” when it comes to dealing with Element objects.

I’ve hoped for a while that Prototype would implement something similar to what JQuery has going on for DOM elements. The current Element object in Prototype is packed full of great stuff, but how you access those methods isn’t exactly ideal.

Previously, you needed to create a variable with the object assigned to it and call the method on that using the Element object. Now, with these latest updates, all it takes is a simple chaining of the calls – even effects can be included. Of course, prototype being the readily-extensible library it is, allows the creation of your own custom Element methods besides the ones it offers that can be called the same way.

For example:


  1. // methods on the Element itself
  2. this.element = $('element');
  3. this.element.hide();
  5. // Scriptaculous effects
  6. $('element').visualEffect('highlight');

For more code examples of this new feature, check out the complete blog entry.

Posted by Chris Cornutt at 8:48 am

3.8 rating from 31 votes


Comments feed TrackBack URI

Yeah, JQuery has some better features than prototype. We all want to get a whole cross browser solution for dom(get/set/update… elements and elements’ properties.)

I really want to get a light GUI lib for my Staight Call using.

Comment by linb — March 10, 2006

[…] Prototype gets some serious syntactic sugar […]

Pingback by Ajaxian » Audible Ajax 16: March State of Ajax — March 14, 2006

Leave a comment

You must be logged in to post a comment.