fix style of range extension, add extendNative()

This commit is contained in:
Sami Samhuri 2011-06-05 18:11:20 -07:00
parent 2dbe210816
commit 930225c297

View file

@ -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;
};