2 ms·
In the first example the genPrimes function is being created 2e4 times, once for each iteration of the loop. In the second example it's defined once.
by Zikes 13y ago
In the first example the genPrimes function is being created 2e4 times, once for each iteration of the loop. In the second example it's defined once.
- lewispollard 13y agoYep, if you use jshint/lint it'll warn you about creating functions within a loop. The performance difference is more to do with that than any inherent flaws in using anonymous functions as callbacks.