3 ms·
Nice work. Have you considered offering your speed improvements as a patch to jQuery?
by fortes 17y ago
Nice work. Have you considered offering your speed improvements as a patch to jQuery?
- jashkenas 17y agoSure, there's not much there to offer. Underscore just delegates to the native implementations of "map", "forEach", "reduce", "reduceRight", "filter", "some", "every", and so on... I bet that jQuery would do the same if they could, but their arguments are incompatible with the native versions -- instead of passing in each element as the first argument to the iterator, jQuery binds the element to "this" for each pass through the iterator. In addition, you can return false from a jQuery loop to break out of the iteration, something that's not supported by the native forEach, and that wouldn't work for "map", in any case. Changing any of this would be a major, backwards-incompatible change... For what it's worth, in Google's Closure Library, they delegate in the same fashion. See "goog.array.forEach", etc.