Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
crisz81916y@olback it iterates on an array. In an ugly way:
$.each(array, function (el) {
// do things
});
in place of:
array.forEach(function (el) {
// do things
}); -
C0D4669026yBecause Jquery.
Plus isn't array.foreach() still a prototype?
Why don't people just write a for() loop instead 🤷♂️ -
C0D4669026y@lknk true, but this is JS, so it shouldn't be looping through thousands of indexes in the first place where the performance of a second temporary variable would have any actual impact.
-
thoxx19776yforEach is an array method, $.each can be used on any type of collection.
They are very differently behaving methods. -
crisz81916yWhat about Array.from(array).forEach()?
Well, it's longer to type, but you avoid importing a heavy library.
The alternative is knowing the fucking variable you are operating on and using the fucking appropriate method -
As someone who's «forced» to use it, I use it simply because I have so much work and so little time that i can't focus on performance, I need to get things done ASAP.
-
@lknk If you're like me and shit at designing you're gonna implement bootstrap which comes with jQuery and if you already have it, why not use it?
-
@lknk yeah beause reading and writing 2 variables is quicker than a function call. Of course for() is faster than foreach. Always. By fucken definition.
-
lknk976y@EdoPhoenix well yeah than i would use it too, but if it‘s not a dependency anywhere i would not add it.
-
KDSBest7716y@C0D4 @lknk u guys know that for is superior in speed to forEach. For is faster and hard to beat for forEach.
It's 2019. Why do people keep using $.each?
rant