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