Skip to content

Commit

Permalink
Reorganize number.js.
Browse files Browse the repository at this point in the history
  • Loading branch information
tobie committed Dec 11, 2008
1 parent 75440aa commit 23b7608
Showing 1 changed file with 39 additions and 15 deletions.
54 changes: 39 additions & 15 deletions src/number.js
Original file line number Diff line number Diff line change
@@ -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
};
})());

0 comments on commit 23b7608

Please sign in to comment.