$w :: Utility Methods

$w(String) -> Array

 

Splits a string into an Array, treating all whitespace as delimiters. Equivalent to Ruby's %w{foo bar} or Perl's qw(foo bar).

 

This is one of those life-savers for people who just hate commas in literal arrays :-)

 

Examples

 

$w('apples bananas kiwis')

// -> ['apples', 'bananas', 'kiwis']

 

This can slightly shorten code when writing simple iterations:

 

$w('apples bananas kiwis').each(function(fruit){

  var message = 'I like ' + fruit

  // do something with the message

})

 

This also becomes sweet when combined with Element functions:

 

$w('ads navbar funkyLinks').each(Element.hide);


Prototype API 1.5.0 - prototypejs.org