forked from prototypejs/prototype
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
39 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
}; | ||
})()); |