mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-01 07:47:49 +00:00
Optimize _.times.
Former-commit-id: beae48853d0e9be1c3016c11bee86a272964dfa2
This commit is contained in:
16
lodash.js
16
lodash.js
@@ -3034,13 +3034,21 @@
|
||||
* @example
|
||||
*
|
||||
* _.times(3, function() { genie.grantWish(); });
|
||||
* // => calls `genie.grantWish()` 3 times
|
||||
*
|
||||
* _.times(3, function() { this.grantWish(); }, genie);
|
||||
* // => also calls `genie.grantWish()` 3 times
|
||||
*/
|
||||
function times(n, callback, thisArg) {
|
||||
var index = -1;
|
||||
if (thisArg) {
|
||||
callback = bind(callback, thisArg);
|
||||
}
|
||||
for (var index = 0; index < n; index++) {
|
||||
callback(index);
|
||||
while (++index < n) {
|
||||
callback.call(thisArg, index);
|
||||
}
|
||||
} else {
|
||||
while (++index < n) {
|
||||
callback(index);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user