From 314e161c5713f8bc75b11a4085e2d339c43c6544 Mon Sep 17 00:00:00 2001 From: Tobie Langel Date: Mon, 29 Sep 2008 23:07:16 +0200 Subject: [PATCH] Reorganize range.js. --- src/range.js | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) 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); -};