Yes if you want all versions of IE dropped as well as Safari.
Or bring in jQuery, small and fast and almost guaranteed to be cached locally anyway, and get it fully compatible in 1 (shorter) line without the lambda "arrow function".
So, in your case, we'd have (works on some browsers):
jQuery, small and fast and almost guaranteed to be cached locally
That you keep claiming this in every comment does not make it any more true. There is a huge fragmentation in jQuery versions, so even if 100% of all jQuery sources were served from the same CDN the chance of them having your particular version cached is not great. See https://www.stevesouders.com/blog/2013/03/18/http-archive-jquery/
That you keep claiming this in every comment does not make it any more true.
Where's that little emoticon with the smiley smashing his head against the wall? :)
Ok, no problem.
There's only one real way to answer this question, and since I don't work in your office ....
What percentage of your bandwidth utilization from the server is currently being taken up by serving jQuery?
Almost no one can answer that, and that is the problem. I can answer it, I know down to a single byte how much the server is sending out jQuery as opposed to the thousands of other things in a given request.
People spend all day worrying about "all these bytes being sent" when they are not looking at the numbers.
If you have the numbers, then you don't even need to be posting this, because you understand what you're doing, as do I.
Anyway I wouldn't be concerned about the speed of forEach vs map.
A lot of people would be!
And therein lies the problem.
Programmers working with JavaScript sometimes seem like they are running the particle colliders at CERN.
When one image on your page is bigger than jQuery, and you are worried about having to "bring in all of jQuery when we only use half of it", you need to take a deep breath and start again.
Who does have to worry about this? The Google's and Facebook's of the world, where a change that is a few bytes more expensive can cost millions of dollars.
So I understand the logical reasoning behind not doing mutations with a functional.method with an emphasis on immutability but in this case I don't see much if a problem would you care to elaborate what's wrong with it?
The intent is no longer clear. .map has a very clear intent - give me a new array with some transform performed to all the elements. Don't mutate the original array.
It communicates conflicting intentions. The map says "any side effects are a mistake and should be put in the bug tracker" while the loop body says "I'm nothing but a side effect." That kind of thing makes the code harder to read for the next person two years down the line.
12
u/puhnitor Jun 10 '16 edited Jun 10 '16