“You Don't Need JQuery” Part 5: Events
blog.garstasio.com
blog.garstasio.com
> If we've heard this argument once we've heard it a million times. Of course you don't need jQuery but unless you are writing an internal-only app and plan on writing everything from the ground up (all your auto-completes, multi-selects, etc) then you do need jQuery.
> I am not a fan of a lot of the code that I've seen written with jQuery but jQuery itself is not evil anymore than PHP is evil because people do stupid stuff with it. If you use jQuery correctly it is an invaluable tool that makes your like 100x easier.
> Event handling alone, I want to puke when I see the default way to do this, way too much typing, way too verbose. If I had to write that multiple times a day then I would probably create a helper function to abstract it away and I'd be on my way to building my own jQuery. No thank you, I'll take the one that's battle-tested and maintained.
> I'm getting sick of seeing this argument, if you work in a bubble then sure, be my guest (I'll be laughing at all the extra typing you will be doing) but if you plan on deploying your code to the real world? Just use jQuery and save yourself a headache.
Good article.
And then the author proceeded to write a function that handles event listening.
And then there is the "Libraries to Consider".
It's ironic the the author demonstrates it clearly that the "modern Web API" is still not ready and we will still be using libraries like jQuery for the next couple of years.
> I fell into a trap, and this is a trap that many new, occassional, and hobbyist web developers fall into. Had I taken the time to understand JavaScript and the API provided by the browser first, I would have saved myself a lot of trouble.
This is the only justification we get from the author for not using jQuery. You can actually learn about the DOM and JavaScript while using jQuery, in fact you have to if you write anything that's more complicated then form validation.
I would say that the actual trap is not using jQuery, just because some people don't think it's "cool" anymore.
Also using jQuery doesn't mean that you cannot the DOM API directly if it makes sense.
If I may toss out a couple of cliches -- why reinvent the wheel when you can stand on the shoulders of giants?
That's only if you point to the exact same version everyone else is using.
My thought process using Spring in Java:
1. I should try to just use pure EE to leverage the power of the web container so I don't include a heavy framework for no reason.
2. Now I have a need that pure EE doesn't solve so well.... Googling for solutions... oh look Spring framework can accomplish this.
3. I might as well go with Spring because it is well-maintained, convenient, & will probably solve some other utility needs that come up anyway. Better to have 1 solution than patchwork of several...
4. Well, now that Spring framework is installed I might as well just refactor some of this code to Spring, it will be slimmer...
Same with jQuery.... if there is effort in learning compensatory methods for a various needs, there usually aren't many valid reasons for not just embracing a major lib/framework. (At this point I pretty much jump straight to step 4 as quickly as possible at the start of projects to avoid the refactor...)
jQuery is actually less intrusive and therefore more of a no-brainer for me! (I know i use Spring as an analogy in my own comment on this thread, but despite being a framework you can use a lot of its libs without committing to any of its other aspects)
sorry for being nitpicky i am just into analogies :)