27 lines
611 B
JavaScript
27 lines
611 B
JavaScript
|
Object.extend(Number.prototype, {
|
||
|
toColorPart: function() {
|
||
|
return this.toPaddedString(2, 16);
|
||
|
},
|
||
|
|
||
|
succ: function() {
|
||
|
return this + 1;
|
||
|
},
|
||
|
|
||
|
times: function(iterator) {
|
||
|
$R(0, this, true).each(iterator);
|
||
|
return this;
|
||
|
},
|
||
|
|
||
|
toPaddedString: function(length, radix) {
|
||
|
var string = this.toString(radix || 10);
|
||
|
return '0'.times(length - string.length) + string;
|
||
|
},
|
||
|
|
||
|
toJSON: function() {
|
||
|
return isFinite(this) ? this.toString() : 'null';
|
||
|
}
|
||
|
});
|
||
|
|
||
|
$w('abs round ceil floor').each(function(method){
|
||
|
Number.prototype[method] = function(){ return Math[method](this); }
|
||
|
});
|