views:

482

answers:

12

I recently discovered jQuery, and I can immediately see how useful and elegant it is.

I'm curious, though - are there any reasons NOT to use it (and just use plain old JavaScript instead)? If there aren't any reasons, should it not be integrated fully into the JavaScript language?

+15  A: 

If you don't actually use any of the features of jQuery, there's no reason to introduce the page weight to your site. If you do use any of the features, there's probably not a good reason to roll your own version except for learning purposes.

Hank Gay
+1 - often a site might need only a little JavaScript to begin, which one can roll on his/her own. As the desire/requirement to do more client side may grow, one can find his/herself needing to write more and more JavaScript and it is at this point that looking at a JavaScript library will save development time, cross browser headaches and the need to write as much code.
Russ Cam
@Russ Cam - (highlighting one view for the discussion): even with only a little JavaScript, why wait? 99% of the time, it's not like adding the JS lib reference is hard, or that another 20kb HTTP request is *really* what will impact the page's client-side performance
orip
+6  A: 

I love JQuery too - so don't get me wrong... but as Devil's Advocate:

  • Not everyone on your team knows JQuery, thus they'd be in a pickle if they inherited your work
  • Not everybody feels that JQuery is the best JavaScript library (more of an argument against making JQuery synonymous with JavaScript)

That said, I personally feel that you should use a JavaScript library (presumably JQuery) rather than recreating equivalent behavior with JavaScript. It's the most popular library and it might be more readable/maintainable than hand-rolled JavaScript.

Mayo
I think they'd often be in more of a pickle if you rolled your own cute UI tricks. jQuery probably has a better chance of working correctly cross-browser than your (well, "my" at least) own code.
Chris Farmer
+4  A: 

Lots of bad reasons. Two good ones:

  1. You don't need it. There are plenty of things you might want to do with JavaScript that don't require or particularly benefit from jQuery.
  2. You don't want it. Personally, I think jQuery is fantastic. Sets, function chaining, concise syntax... it all makes me happy. But, some folks have different tastes.
Shog9
Two good bad reasons? heh ;)
Neil N
+4  A: 

jQuery is built on javascript and encapsulates a particular style of programming and a set of supported features. Not everyone wants to use this style of programming or prefers the set of features in jQuery over those in other frameworks. jQuery is certainly an improvement over coding the same features yourself in plain javascript, but not necessarily a substitute for all javascript as the feature set is finite. You'll still need to write some plain javascript when using jQuery (or any other framework).

tvanfosson
+9  A: 

are there any reasons NOT to use it

  • There are better libraries.
  • It adds page weight (and for small projects that weight is often more costly then the benefits)

should it not be integrated fully into the Javascript language?

Most of what jQuery does is related more to DOM than JavaScript.

David Dorward
"There are better libraries" - recommendations? (I know it's subjective, but still)
orip
I'm curious, too.
MiseryIndex
I was deliberately not being specific because it is subjective (and context sensitive)
David Dorward
MooTools would be a good example IMO.
BYK
I too love mootools but my opinion is that the more live testing goes into a library the better it gets. jQuery is tested to a much higher degree than mootools (unfortunately because I'm very found of Moo). Look at my last question, http://stackoverflow.com/questions/1808119/ie8-crash-on-getstyle-background-position a Mootools problem that jQuery does not have.
Frankie
Saying "There are better libraries" is pretty unhelpful. It really depends on the matter at hand. jQuery trumps all libraries for some tasks, and falls flat on its face for other tasks.
J-P
@J-P: As I said: "it is subjective (and context sensitive)"
David Dorward
+3  A: 

I can say it in one word: overhead. It adds another 19K to your page.

Don't get me wrong, this is a sick library - I use it all the time.

Jacob Relkin
Does 'sick' mean good? :)
Chetan Sastry
Luckily you can put all that extra-effort on Google! Yeehey! ;)
Frankie
Um, it doesn't mean 'good' - it means 'awesome'.
Jacob Relkin
'sick' in that sense is not common usage, i thought you meant 'slick'
Jason S
It's slick too, you know.
Jacob Relkin
A: 

jQuery is developed and is still being developed for the very entry level developer. Actually it is almost built for non-developers so it makes some things very easy BUT with a performance trade.

It does many things right and it does many things wrong for various reasons like:

  • The above mentioned "stupid-proof" structure
  • Taste of jQuery team
  • Extensive(but a bit overkill) cross-browser capabilities

So I personally prefer some other library written for JS Ninjas for better performance. I actually went as far as creating my own library but that's another issue.

BYK
It does many things right and it does many things wrong - great statement but you give neither any meat.....explain
redsquare
A: 

I think choosing a JS & DOM & AJAX library you like is important, and it will almost always be appropriate to use said library, but don't let that stop you for learning important JavaScript features, idioms & techniques, as well as some browser and DOM API.

Being afraid to leave your library's boundaries is very limiting.

orip
+4  A: 

One reason - to actually learn javascript.

It is a truly beautiful language that is often overlooked, because when people say "I know javascript", what they actually mean is "I know how to copy&paste $('#content').hide(200) to make my app look cool".

This is a bit sad.

That being said (no pun intended), I use jquery all the time for mundane tasks like xhr, DOM manipulation and such. Unfortunately, there is absolutely no reason to reinvent the wheel (more than one time, anyway), especially taking into consideration the fact, that, at times, you have to invent a separate wheel for every major browser.

shylent
I vote for not reinventing the wheel at all. Great post.
Jacob Relkin
Well, in my opinion it is quite O.K. to invent any particular wheel once, because that makes you understand how other wheels of such types work. I mean, noone forces you to use your "home-made" solution in production. But it certainly does help to understand the underlying logic of a framework/language/etc (not talking about only jquery and javascript here).
shylent
+3  A: 

Sure, there are lots of reasons to choose plain Javascript over a great library like jQuery.

  • You're getting paid by the hour
  • You hate yourself
  • ...

...oh. Well, I guess there aren't lots. But there are some. :)

Nathan Long
A: 

I've used Jquery a few times, and it's just so damn easy compared to using dom. It also seems like it has more accessability than old fashioned DOM.

In the words of Martha Stewart, "It's a good thing."

Inserter
A: 

PLEASE, use jquery and only jquery, and the extensions that are made for jquery. You'll never need anything else.

signed. a friend

classic