Tuesday, September 25th, 2007

Reiterate: Symbol#to_proc for JavaScript

Category: JavaScript, Library, Prototype

James Coglan has ported ideas from ideas from Ruby’s Symbol#to_proc and Methodphitamine to create Reiterate, a library for Prototype.

The library means that instead of code like this:

javascript

  1. var value = radioGroup.find(function(radio) {
  2.   return radio.checked;
  3. }).value;
  4.  
  5. var divs = someDivs.findAll(function(div) {
  6.   return div.hasClassName('myClass') && div.visible();
  7. });

you can write:

javascript

  1. var value = radioGroup.find('checked').value;
  2.  
  3. var divs = someDivs.findAll({hasClassName: 'myClass', visible: true});

Download Reiterate.

Posted by Dion Almaer at 8:47 am
14 Comments

+++--
3.2 rating from 29 votes

14 Comments »

Comments feed TrackBack URI

Enumerable on steroids! This syntax is truly amazing…

Comment by kangax — September 25, 2007

Looks like the first steps in making prototype operate like jquery.

Comment by Glen — September 25, 2007

forget jqueery.

Comment by Mike — September 25, 2007

have you guys tried moo?

sorry, couldn’t resist.

Comment by Steve — September 25, 2007

@Glen, you must mean more like ruby. This has nothing todo with another framework, ktnxbye

Comment by Trulli — September 25, 2007

@Steve: how can I go to my boss and tell him we should try a library called ‘Moo Tools’? You guys need a better name to be taken seriously.

Comment by Les — September 25, 2007

@Les, i was just kidding about the moo comment. i think the framework wars are pretty silly (as is the name “moo”)

Comment by Steve — September 25, 2007

@Glen: indeed, I had some strange déja vu feeling ;-)

Comment by Frank Thuerigen — September 25, 2007

@Steve and @Frank: mootools = my object oriented tools, if your boss makes his decisions based on how cool of a name something has, then I suggest you find a new job … since the company won’t be around for much long.

Comment by Marat Denenberg — September 25, 2007

Woopsie … I need more sleep … above comment for Steve and Les … sorry Frank … blah! Ajaxian needs a better comment system, like the one on Engadget, where you can reply to comments.

Comment by Marat Denenberg — September 25, 2007

jquery

Comment by Micox — September 25, 2007

@Marat

Considering that Ruby on Rails is usually used based on the name or hype rather than an actual business case, maybe judging by a name isn’t so bad. ;-)

Plus, mootools sounds pretty cool.

Comment by Andy Kant — September 25, 2007

You could just call it “moot-ools”. Now that is just Moot ools of fun… :)

Comment by Mike Kidder — September 25, 2007

Thanks for that
ha ha

Comment by Remedies — December 8, 2008

Leave a comment

You must be logged in to post a comment.