mirror of
https://github.com/samsonjs/batteries.git
synced 2026-03-25 09:15:46 +00:00
fix style of range extension, add extendNative()
This commit is contained in:
parent
2dbe210816
commit
930225c297
1 changed files with 17 additions and 13 deletions
30
lib/range.js
30
lib/range.js
|
|
@ -3,24 +3,28 @@
|
|||
|
||||
exports.Range = Range;
|
||||
|
||||
exports.extendNative = function() {
|
||||
global.Range = Range;
|
||||
};
|
||||
|
||||
function Range(start, length) {
|
||||
this.start = start;
|
||||
this.length = length;
|
||||
this.start = start;
|
||||
this.length = length;
|
||||
};
|
||||
|
||||
Range.prototype.inRange = function(val) {
|
||||
if (this.test) return this.test(val);
|
||||
return val >= this.start && val <= this.start + this.length;
|
||||
if (this.test) return this.test(val);
|
||||
return val >= this.start && val <= this.start + this.length;
|
||||
};
|
||||
|
||||
Range.prototype.toArray = function(nth) {
|
||||
var a = []
|
||||
, i = this.length
|
||||
;
|
||||
nth = nth || this.nth;
|
||||
if (nth)
|
||||
while (i--) a[i] = nth(i);
|
||||
else
|
||||
while (i--) a[i] = this.start + i;
|
||||
return a;
|
||||
var a = []
|
||||
, i = this.length
|
||||
;
|
||||
nth = nth || this.nth;
|
||||
if (nth)
|
||||
while (i--) a[i] = nth(i);
|
||||
else
|
||||
while (i--) a[i] = this.start + i;
|
||||
return a;
|
||||
};
|
||||
|
|
|
|||
Loading…
Reference in a new issue