Prototype

From Wiki
Jump to navigation Jump to search

http://www.prototypejs.org/api

Array

iterate over an array:

myArray.each(function(item) {
  // Your code working on item here...
})  // notice placement of parens

append to an array:

myArray.push(newValue)

Hash

iterate over a hash:

myHash.each(function(pair) {
  // do something with pair.key and pair.value
})  // notice placement of parens

String

interpolate text:

"#{animals} on a #{transport}".interpolate({ animals: "Pigs", transport: "Surfboard" });
//-> "Pigs on a Surfboard"