From f64c9568c87c70d3f7eef70e78542a8c7978537b Mon Sep 17 00:00:00 2001 From: Tobie Langel Date: Mon, 29 Sep 2008 23:06:54 +0200 Subject: [PATCH] Reorganize number.js. --- src/number.js | 54 +++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 39 insertions(+), 15 deletions(-) diff --git a/src/number.js b/src/number.js index 0da58b1..8fea757 100644 --- a/src/number.js +++ b/src/number.js @@ -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(); -}); \ No newline at end of file + + 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 + }; +})());