diff --git a/src/number.js b/src/number.js index 5a2b939..0da58b1 100644 --- a/src/number.js +++ b/src/number.js @@ -7,8 +7,8 @@ Object.extend(Number.prototype, { return this + 1; }, - times: function(iterator) { - $R(0, this, true).each(iterator); + times: function(iterator, context) { + $R(0, this, true).each(iterator, context); return this; }, diff --git a/test/unit/number_test.js b/test/unit/number_test.js index 662d828..4e09529 100644 --- a/test/unit/number_test.js +++ b/test/unit/number_test.js @@ -30,5 +30,15 @@ new Test.Unit.Runner({ this.assertEqual('null', Number.NaN.toJSON()); this.assertEqual('0', (0).toJSON()); this.assertEqual('-293', (-293).toJSON()); + }, + + testNumberTimes: function() { + var results = []; + (5).times(function(i) { results.push(i) }); + this.assertEnumEqual($R(0, 4), results); + + results = []; + (5).times(function(i) { results.push(i * this.i) }, { i: 2 }); + this.assertEnumEqual([0, 2, 4, 6, 8], results); } }); \ No newline at end of file