Monday, December 12th, 2005

Prototype Meets Ruby: A Look at Enumerable, Array and Hash

Category: Articles, Prototype

A lot of the open source Ajax frameworks need a bit more on the documentation don’t they

Justin Palmer has gone through and documented some of the features that Prototype adds to your JavaScript experience.

Iterating over an array

someArray.each(function(num) {
  logger.info(num);
});

Exposing Hash Key/Value pairs

$H(F.Products[0]).each(function(product) {
  logger.info(product.key + ": " + product.value);
});

Collect

var companies = F.Products.collect(function(product) {
  return product.company;
});
logger.info(companies.join(', '));

and others such as include, inject, findAll, detect, invoke.

via Thomas Fuchs

Posted by Dion Almaer at 12:34 am
Comment here

++---
2.6 rating from 10 votes

Comments Here »

Comments feed

Leave a comment

You must be logged in to post a comment.