Number
Upcoming SlideShare
Loading in...5
×
 

Like this? Share it with your network

Share

Number

on

  • 378 views

Prototype Javascript

Prototype Javascript

Statistics

Views

Total Views
378
Views on SlideShare
378
Embed Views
0

Actions

Likes
0
Downloads
3
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

Number Presentation Transcript

  • 1. Module Number
  • 2. Number
    • Prototype extends native JavaScript numbers in order to provide:
    • 1)ObjectRange compatibility, through a succ method.
    • 2) Ruby-like numerical loops with a times method.
    • 3) Simple utility methods such as toColorPart.
  • 3. Number
    • Examples;
    • 1) $R ( 1 ,  10 ).each( function ( index ) {
    •      // This gets invoked with index from 1 to 10, inclusive});
    •   2) ( 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 });
    • 3) 128.toColorPart()
    • // -> '70‘
    • 4)  '#' + [128, 10, 16].invoke('toColorPart').join('')
    • // -> '#800a10'
  • 4. Number
    • succ() -> Number
    • Returns the successor of the current Number, as defined by current + 1. Used to make numbers compatible with ObjectRange .  
    • Examples;
    • 1) ( 5 ).succ()
    • // -> 6
    • 2) $A($R(1, 5)).join('')
    • // -> '12345'
  • 5. Number
    • times(iterator) -> Number
    • Encapsulates a regular [0..n[ loop, Ruby-style.
    • The callback function is invoked with a single argument, ranging from 0 to the number, exclusive.
    • Example;
    • var  s =  '' ;
    • ( 5 ).times( function (n) {
    •    s += n;
    • });
    • s // -> '01234'
  • 6. Number
    • 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.
    • Examples;
    • 1) 128.toColorPart()
    • // -> '70‘
    • 2) 10.toColorPart()
    • // -> '0a'
    • 3) #'  + [ 128 ,  10 ,  16 ].invoke('toColorPart').join('')
    • // -> '#800a10'
  • 7. Number
    • toPaddedString(length[, radix]) -> String
    • Converts the number into a string padded with 0s so that the string’s length is at least equal to length. Takes an optional radix argument which specifies the base to use for conversion.
    • Examples:
    • 1) ( 13 ).toPaddedString( 4 );
    • // -> '0013‘
    • ( 13 ).toPaddedString( 4 ,  16 )
    • // -> '000d'