add #times utility method.

_(3).times(alert)

added tests and internal docs
This commit is contained in:
Mike Frawley
2010-02-17 10:21:59 -06:00
parent 263b1ee92d
commit 5a5e14d7a4
3 changed files with 19 additions and 1 deletions

View File

@@ -589,6 +589,13 @@
_.identity = function(value) {
return value;
};
// run a function n times.
// looks good in wrapper form:
// _(3).times(alert)
_.times = function (n, fn, context) {
for (var i=0; i < n; i++) fn.call(context, i)
};
// Break out of the middle of an iteration.
_.breakLoop = function() {