Number

Prototype extends native JavaScript numbers in order to provide:

· | ObjectRange compatibility, through a succ method.

· | Ruby-like numerical loops with a times method.

· | Simple utility methods such as toColorPart.

On this page

· | What becomes possible

· | Moduleindex

What becomes possible

$R(1, 10).each(function(index) {

// This gets invoked with index from 1 to 10, inclusive

});

(5).times(function(n) {

// This gets invoked with index from 0 to 5, *exclusive*

// The parentheses are due to JS syntax, if we did not use a literal, they'd be superfluous

});

128.toColorPart()

// -> '70'

10.toColorPart()

// -> '0a'

'#' + [128, 10, 16].invoke('toColorPart').join('')

// -> '#800a10'

Moduleindex

succ

succ() -> Number

Returns the successor of the current Number, as defined by current + 1. Used to make numbers compatible with ObjectRange.

times

times(iterator) -> Number

Encapsulates a regular [0..n[ loop, Ruby-style.

toColorPart

toColorPart() -> String

Produces a 2-digit hexadecimal representation of the number (which is therefore assumed to be in the [0..255] range). Useful for composing CSS color strings.

Prototype API 1.5.0 - prototypejs.org