Friday, March 10th, 2006

Prototype Gets Some Serious Syntactic Sugar

Category: Programming, Prototype

According to this post on Encytemedia.com, 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 Script.aculo.us 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:

javascript

  1. // methods on the Element itself
  2. this.element = $('element');
  3. this.element.hide();
  4.  
  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
2 Comments

+++--
3.8 rating from 31 votes

2 Comments »

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.