Most of what I used jQuery for was working around browser incompatibility. As IE11 becomes the trailing edge browser we need to support, the need for jQuery shrinks to zero. Once fetch becomes universal, there's not really anything left.
As IE11 becomes the trailing edge browser we need to support, the need for jQuery shrinks to zero.
Not true, because they can slim down jQuery (as you see with 3.0) which still allows you to turn what might be 20 lines of ECMA-compliant JavaScript into a one-liner that even assures you much better compatibility.
It's still useful, as long as it's not bloated, and fast.
It makes your own code more readable ... the whole "DRY principle".
This?
var d = document.getElementsByClassName("goodbye");
var i;
for (i = 0; i < d.length; i++) {
d[i].className = d[i].className + " selected";
}
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):
No particular reason other than the fact that I can be a little cynical and part of me believes the community will opt for map simply because it's shorter and "cooler" to use functional programming techniques. The fact that there is nothing in Javascript (that I know of anyway) to enforce referential transparency means that use of the FP techniques will likely be little more than lip service to the concepts.
I'm pretty hard on the Scala and Haskell communities when it comes to being able to make FP practical and accessible for everyday use, but at least they understand how to get the benefits of FP. I currently do not have any such confidence in the Js community.
I'm not sure, I might quite possibly have misinterpreted (apologies if that's the case), but just in case, the motivation behind not using map and reduces to perform mutations isn't out of an idealistic "functional programming is good" or "mutations are bad" dogma. It's for the benefit of making your code easier to understand for yourself and others
Specifically, it's an implicit promise that the code inside the function, no matter how complex, can be safely ignored as long as the value it returns is as expected. There is huge value in being able to rely on the (albeit implicit) referential transparency for maps and reduces in the amount of code you can skip when you're combing for bugs or trying to understand a section of a program someone else wrote.
And I can tell you of one way of enforcing referential transparency - code review :)
I've run into a few javascript programmers who've made the same mistake with misusing map (2 juniors and one self-taught rockstar), but after I've explained it the responses were always immediately "that makes sense". That gives me hope that while it may be an easy mistake to make, it won't get touted as a best practice because people will understand why they shouldn't be doing it as soon as you explain it to them, and hopefully pass it forward :)
43
u/earthboundkid Jun 09 '16
Most of what I used jQuery for was working around browser incompatibility. As IE11 becomes the trailing edge browser we need to support, the need for jQuery shrinks to zero. Once
fetchbecomes universal, there's not really anything left.