Reorganize number.js.

This commit is contained in:
Tobie Langel 2008-09-29 23:06:54 +02:00
parent 1669e41cda
commit f64c9568c8
1 changed files with 39 additions and 15 deletions

View File

@ -1,27 +1,51 @@
Object.extend(Number.prototype, {
toColorPart: function() {
Object.extend(Number.prototype, (function() {
function toColorPart() {
return this.toPaddedString(2, 16);
},
}
succ: function() {
function succ() {
return this + 1;
},
}
times: function(iterator, context) {
function times(iterator, context) {
$R(0, this, true).each(iterator, context);
return this;
},
}
toPaddedString: function(length, radix) {
function toPaddedString(length, radix) {
var string = this.toString(radix || 10);
return '0'.times(length - string.length) + string;
},
}
toJSON: function() {
function toJSON() {
return isFinite(this) ? this.toString() : 'null';
}
});
$w('abs round ceil floor').each(function(method){
Number.prototype[method] = Math[method].methodize();
});
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
};
})());