Prototype

From Wiki
Revision as of 23:01, 31 January 2011 by Scott (talk | contribs) (Created page with 'http://www.prototypejs.org/api == Array == iterate over an array: <source lang="javascript"> myArray.each(function(item) { // Your code working on item here... }) // notice …')
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
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"