2008-09-29 21:06:54 +00:00
|
|
|
Object.extend(Number.prototype, (function() {
|
|
|
|
function toColorPart() {
|
2007-06-06 16:10:16 +00:00
|
|
|
return this.toPaddedString(2, 16);
|
2008-09-29 21:06:54 +00:00
|
|
|
}
|
2007-06-06 16:10:16 +00:00
|
|
|
|
2008-09-29 21:06:54 +00:00
|
|
|
function succ() {
|
2007-06-06 16:10:16 +00:00
|
|
|
return this + 1;
|
2008-09-29 21:06:54 +00:00
|
|
|
}
|
2007-06-06 16:10:16 +00:00
|
|
|
|
2008-09-29 21:06:54 +00:00
|
|
|
function times(iterator, context) {
|
2008-05-05 13:17:08 +00:00
|
|
|
$R(0, this, true).each(iterator, context);
|
2007-06-06 16:10:16 +00:00
|
|
|
return this;
|
2008-09-29 21:06:54 +00:00
|
|
|
}
|
2007-06-06 16:10:16 +00:00
|
|
|
|
2008-09-29 21:06:54 +00:00
|
|
|
function toPaddedString(length, radix) {
|
2007-06-06 16:10:16 +00:00
|
|
|
var string = this.toString(radix || 10);
|
|
|
|
return '0'.times(length - string.length) + string;
|
2008-09-29 21:06:54 +00:00
|
|
|
}
|
2007-06-06 16:10:16 +00:00
|
|
|
|
2008-09-29 21:06:54 +00:00
|
|
|
function toJSON() {
|
2007-06-06 16:10:16 +00:00
|
|
|
return isFinite(this) ? this.toString() : 'null';
|
|
|
|
}
|
2008-09-29 21:06:54 +00:00
|
|
|
|
|
|
|
function abs() {
|
|
|
|
return Math.abs(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
function round() {
|
|
|
|
return Math.round(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
function ceil() {
|
|
|
|
return Math.ceil(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
function floor() {
|
|
|
|
return Math.floor(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
toColorPart: toColorPart,
|
|
|
|
succ: succ,
|
|
|
|
times: times,
|
|
|
|
toPaddedString: toPaddedString,
|
|
|
|
toJSON: toJSON,
|
|
|
|
abs: abs,
|
|
|
|
round: round,
|
|
|
|
ceil: ceil,
|
|
|
|
floor: floor
|
|
|
|
};
|
|
|
|
})());
|