Rob Kinyon - Number.toColorPart-0.02

Documentation | Source

NAME

Number.toHex

DESCRIPTION

This provides a new method to the core class Number. The method, called toHex(), is used to convert a number into hex.

DEPENDENCIES

This requires JSAN to be installed.

CORE CLASS EXTENSIONS

These are extensions to core classes provided by JavaScript.

Number.toHex()

The toHex() method is added to the builtin Number class, providing a conversion between the number and a hex value suitable for use in HTML color definitions.

CAVEATS

Modifying the prototype of core Javascript classes should be avoided, if possible. By doing this, you are modifying ALL objects of this class, regardless of when they were instantiated or by whom, For some classes, such as Number and String, this includes primitives. This can lead to surprising effects and action-at-a-distance.

You have been warned.

SUPPORT

Currently, there is no mailing list or IRC channel. Please send bug reports and patches to the author.

AUTHOR

Rob Kinyon (rob.kinyon@iinteractive.com)

Originally written by Sam Stephenson (sam@conio.net)

My time is generously donated by Infinity Interactive, Inc. http://www.iinteractive.com

/*

=head1 NAME

Number.toHex

=head1 DESCRIPTION

This provides a new method to the core class Number. The method, called toHex(), is used to convert a number into hex.

=head1 DEPENDENCIES

This requires JSAN to be installed.

=cut

*/

/*

=head1 CORE CLASS EXTENSIONS

These are extensions to core classes provided by JavaScript.

=cut

*/

/*

=head2 Number.toHex()

The C<toHex()> method is added to the builtin Number class, providing a conversion between the number and a hex value suitable for use in HTML color definitions.

=cut

*/

if ( ! Number.prototype.toHex ) {
    Number.prototype.toHex = function() {
        var digits = this.toString(16);
        if (this < 16) return '0' + digits;
        return digits;
    };
}


/*

=head1 CAVEATS

Modifying the prototype of core Javascript classes should be avoided, if possible. By doing this, you are modifying B<ALL> objects of this class, regardless of when they were instantiated or by whom, For some classes, such as Number and String, this includes primitives. This can lead to surprising effects and action-at-a-distance.

You have been warned.

=head1 SUPPORT

Currently, there is no mailing list or IRC channel. Please send bug reports and patches to the author.

=head1 AUTHOR

Rob Kinyon (rob.kinyon@iinteractive.com)

Originally written by Sam Stephenson (sam@conio.net)

My time is generously donated by Infinity Interactive, Inc. L<http://www.iinteractive.com>

=cut

*/