diff --git a/src/range.js b/src/range.js index 0d750f2..f29ecde 100644 --- a/src/range.js +++ b/src/range.js @@ -1,27 +1,34 @@ -var ObjectRange = Class.create(Enumerable, { - initialize: function(start, end, exclusive) { +function $R(start, end, exclusive) { + return new ObjectRange(start, end, exclusive); +} + +var ObjectRange = Class.create(Enumerable, (function() { + function initialize(start, end, exclusive) { this.start = start; this.end = end; this.exclusive = exclusive; - }, + } - _each: function(iterator) { + function _each(iterator) { var value = this.start; while (this.include(value)) { iterator(value); value = value.succ(); } - }, + } - include: function(value) { + function include(value) { if (value < this.start) return false; if (this.exclusive) return value < this.end; return value <= this.end; } -}); + + return { + initialize: initialize, + _each: _each, + include: include + }; +})()); -var $R = function(start, end, exclusive) { - return new ObjectRange(start, end, exclusive); -};