Add context argument to Number#times
This commit is contained in:
parent
49b921a5c7
commit
15b43b7633
|
@ -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;
|
||||
},
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
});
|
Loading…
Reference in New Issue