views:

519

answers:

14

I've been following the javascript questions here for the last few weeks, and I've found a common recurring theme.

Almost any question asked on here that involves JavaScript gets answered with:

  1. "jQuery can do that"
  2. "there's a plugin for that"
  3. "jQuery can make your bed for you."

Even questions referencing other libraries are answered by saying "Use jQuery instead".

Is jQuery replacing JavaScript as a whole?
This is a serious question. Are we really looking at JavaScripts future. Obviously this community has a strong bias towards jQuery (is that because there's alot of .NET developers?), but does the web development community as a whole share this bias?

+19  A: 

No, jQuery does not replace JavaScript, because it is JavaScript. But it helps you a lot, especially in selecting elements and applying functions on elements.

The probably most important argument for using jQuery: You don't have to think about cross-browser compatibility.
Seriously, the different JavaScript implementations in the browsers are driving me crazy.

But I also don't think jQuery should be used for everything. It depends on where (e.g. which browsers) the JavaScript is used and what you actually do.

And as I already answered on other question, you can only master jQuery if you understand JavaScript. It is very easy to write bad jQuery code if you don't understand how it works.

Update:

In fact in modern browsers you can already do stuff you normally used jQuery for, like using selectors or each(), natively in JavaScript, with document.querySelectorAll() and the array method forEach().
But this is the problem: In modern browsers. jQuery ensures that you can use the same API and don't have to care about the browser version.

Felix Kling
Really, if Javascript were redesigned from the start, it would look a lot more like jQuery than it would Javascript
BlueRaja - Danny Pflughoeft
Other jQuery (cross browser) benefits: Reliable selectors, Reliable event handlers, Reliable AJAX, strong plugin architecture, useful utility functions.
gnarf
@BlueRaja - Danny Pflughoeft: Some methods are on the way, see my updated answer. @gnarf: True, the easy usage of Ajax is probably one the most important features in the so called "Web 2.0".
Felix Kling
Exactly. When you are knee deep in clients who expect things to go smoothly across all browsers and versions of browsers...doing it w/out a framework is fine, but you have all these conditions to check for diff browsers and versions and execute slightly different code accordingly. Pretty soon you throw it all into a function, your own "library", because you find yourself doing the same thing over and over. That is about half of what jQuery is. The other half is making your life easier as far as applying javascript to things. Need to apply an event listener to all links on the page?
Crayon Violent
(cont'd)...Or just links within a certain area? It's time consuming and frustrating doing all that by hand, or writing out loops and getElementByTag/ID/etc.. and then have to make it cross-browser compatible to boot. TBH it has been my experience that most people who shy away from frameworks like jQuery usually don't have a whole lot of javascript experience in general to begin with. Just sayin'...
Crayon Violent
And no, I do not think jQeuery (or any other framework for that matter) needs to be used for EVERYTHING. It really depends on what your project/needs are. But if you are already using it and it's thrown in a global include, no reason not to, even if it's not strictly necessary.
Crayon Violent
I am against this post based on this line "You don't have to think about cross-browser compatibility." I have found that jquery itself is this way. However, this sort of bias makes users of jquery overly trusting of plugins written for jquery. These plugins sometimes good but the cross browser compatibility of jquery is often lost when people write their jquery plugins. Also if you want an example of jquery itself of not being cross browser try injecting some custom xml into a jquery object and run some selectors to extract data. It will work in firefox and not in IE.
Jonathan Park
@Jonathan: Well, jQuery itself cannot be made responsible for bad plugins. And there might be special cases where jQuery does not work well. But I assume that for most of the cases it is compatible enough. Just think about easy stuff like `document.getElementsByClassName()` that does not even exist up to and including IE8. But you are right, you still have to know what its limitations are.
Felix Kling
@Felix: I fully understand the benefits of jquery as whole. I just don't like that people recommend it as a stepping stool to using javascript. It is quite easy to misuse this tool in non cross browser ways and I am fully against any statement that makes light of browser compatibility.
Jonathan Park
+3  A: 

Well I can't speak for everyone but jquery just makes javascript tasks easier. Not to mention that they are tested across multiple browsers so less concern with cross-compliant issues.

What you could write in 1 line of jquery could take you 10 or more with writing your own javascript. Also the benefit of using the library is that it has been tested for bugs that you don't have to worry about.

Just my opinion.

spinon
A: 

jQuery has become a defacto standard, the way that C or Java is for the desktop programming world - everyone knows it, or should as it provides common language. Typically everyone starts on jQuery and then learns about Javascript from their experiences and can look elsewhere.

Javascript is hard, and jQuery makes it easy to get started. Once people learn jQuery, they will be familiar with Javascript enough to learn the other frameworks or create their own minimilistic ones. But alas you could learn something else instead, but generally the learning curve is bigger.

Some other really popular ones are MooTools and SproutCore - both of which have HUGE backing. jQuery is kinda like training wheels for javascript, MooTools is OO all the way, and SproutCore is for desktop apps in the cloud. Just like any programming language or framework, you learn the easiest one to get started, then as you get better you realise that different languages and frameworks are better for different things - or at least you should realise that ;-) hehe.

balupton
Shocking in what way?
Josh
I always found that the cross browser support in it was really poor. Originally I had built my Lightbox plugin using Prototype, and I just spent a ton of time than not trying to debug the weirdest errors in the strangest circumstances. Which is why I moved to jQuery. These days I use jQuery mainly and MooTools every now and then. But then again, I haven't touched prototype for about 2 years now...
balupton
I disagree (but it wasn't me that -1'd... everyones entitled to their opinion). People should learn JavaScript before jQuery. I believe its people that take your approach that come on here and ask the most ridiculous and basic JavaScript questions, simply because they aren't familiar typing code that hasn't got a $ in it, and don't understand the JavaScript involved when they type their $.
Matt
+17  A: 

I sort of have a bias against jQuery. It's my only ignored tag :)...

In my opinion, it is inappropriate for people to post into other questions saying "Can I haz jQueries?" when the other person is into "plain" JavaScript, though.

I believe that everyone should learn "plain" javascript+dom manipulation BEFORE going into jQuery, sort of like how you shouldn't jump straight into DirectX when you learn c++; you can't work with jQuery without JavaScript know-how...

In the end, though, you should use what you feel more comfortable with.

But in all honesty, I believe that you will have more opportunities if you also become proficient at JavaScript, and let's say jQuery does die out one day... Your experience with JavaScript itself will still be there.

ItzWarty
`I believe that everyone should learn "plain" javascript+dom manipulation BEFORE going into jQuery.` Quoted for truth!
George Marian
`$('.I').('.can:has(jQueries)').delay(NONE!!!)`
Peter Ajtai
If the question doesn't mention jQuery, I'll often supply an answer that doesn't use jQuery. If its an operation that would be made easier by jQuery, I'll provide that code as a reference as well.
gnarf
I am an avid jquery user and think it is actually pretty much the answer to all things javascript. However, I am bumping your answer because jquery has become so popular and well supported that most people have stopped learning actual javascript before utilizing this great tool.
Jonathan Park
+4  A: 

As I see it, JavaScript is ugly, error prone and a pain. I love the flexibility that allows for approaches such as jQuery, prototype.js, etc. However, the emergence of these libraries proves my point. Not all of this is JavaScript's fault. Some of it is due to the web browsers.

To better answer the actual question:

jQuery just makes things easier, like any good library/framework should. This is the reason it gets suggested so much. It's just easier to do it in jQuery than plain JavaScript. Trying to explain all the minutiae to get plain JavaScript to work in a variety of situations can be a serious pain.

That said, I agree. If someone is looking for just a JavaScript solution, that is what they should get. However, they should realize that it could be a difficult process and not everyone has the time/interest to go to that much trouble.

George Marian
It's not JavaScript that's "ugly, error prone and a pain". It's the DOM. If you use a library, you're still writing JavaScript.
Tim Down
@tim That's a fair point. To which I respond, why can't I have "real" OO? What's this prototype crap? (Yes, I know, JS is a prototype language. Which, IMO, is just plain ugly, error prone and a pain.)
George Marian
@tim To expand on that point: Global variables, by default, and -- *mostly* -- optional line terminators. One of the most recommended JavaScript books, right here on SO, is titled "Javascript: The Good Parts." Yes, the DOM is ugly, but that doesn't make JavaScript beautiful.
George Marian
Yes, I agree JavaScript has flaws, including various aspects of global variables (assignment to an undeclared variable within a function silently creating what is in effect a global variable, for example). I rather like prototypal inheritance, perhaps because I've always done JavaScript alongside Java and C#, so I can't agree with you there. I too like Crockford's book, but if SO is a good guide then I think there's an unhealthy tendency among JavaScript developers to take his word as gospel: much of what he classes as good and bad is his own opinion, and I disagree with some of it.
Tim Down
+2  A: 

I can't speak for the bias toward a particular framework, but usually using a framework trumps vanilla javascript when it comes to getting things done, and done right. David Walsh said it best here:

http://davidwalsh.name/6-reasons-to-use-javascript-libraries-frameworks

That said, I'm a PHP dev who's in love with jQuery. As soon as I switched from Mootools, I never looked back.

Stephen
A: 

because jquery is awesome.

Tobias
A fanboy-ish attitude doesn't help the conversation in any way.
ItzWarty
@ItzWarty: EDIT: Miss the period so deleted, but yea, I get where you are coming at, having 10 posts like this would just be stupid. Thanks for calling me out on it via my post. It will make me think twice before posting something stupid and unrelevant to the topic at hand.
Brad F Jacobs
izywarty: occam's razor.
Tobias
+1  A: 

If you're just using JavaScript to manipulate the DOM and do AJAX, why not use a framework to do the heavy lifting and grunt work?

JavaScript does extend beyond web pages and the DOM too. See node.js for some serious awesomeness. For a small peek read this blog post (though it is more impressive with more people on at once).

swilliams
+1  A: 

It's the same thing as asking why there is a preference towards using any framework such as MVC .net, CakePHP etc. Speed, flexibility, reuse etc.

However, although frameworks do a whole bunch of cool stuff, in the end it doesn't replace the need to know and understand underlying language.

xiaohouzi79
+1  A: 

To me, jQuery is sort of like Cocoa for the Mac. I have read that the Cocoa framework is composed simply of many "low-level" Unix commands that are the base of the Mac OS. So when you do something as simple as allocating memory, these long-lost simple commands are run.

I would not be surprised if the progression from Unix to Cocoa were to happen to Javascript into jQuery — after all, it would be easier to call a jQuery command that internally did 10 basic Javascript actions (especially if the command was commonly used). Personally, I am against it, because it limits the freedom of the developer. While others might argue it allows more creativity because it's easier/faster to build new/better things, people will rely on it, and eventually become dependent, and forget all about the basic core of Javascript.

What if a specific "handy-dandy, pre-made and ready-to-use" function for what you wanted didn't exist in the merry "simple" world of jQuery? If developers relied on jQuery, they'd be at a total loss. In my opinion, we developers must continue to be independent and create our own code, though using a little pre-made stuff doesn't hurt either.

pop850
+1  A: 

A following says a lot about an API or Framework. In general, more users will tend to generate better documentation. Documentation can go a long way in the adoption process.

jQuery does have its limitations, at least at the time of the writing of this answer. For example, today I wanted to test functionality with a xhr that stays at readystate 3 most of the time. I decided I might be better off writing my own jQuery plugin instead of using the $.ajax that is commonly used. That wouldn't have been such a bad thing. However, I've come to appreciate that jQuery is tested on many versions of many different browsers. I can hit a target usability audience just by using one framework.

In the end, I could have experimented with $.ajax beforeSend to see if there was a way to attach a handler for readystate 3, but the documentation I was reading led me to believe that it would have been more work for the task I needed to accomplish.

Overall, I have to say that I've enjoyed jQuery more than the other frameworks I've tried. When something else comes along, I'll give it a try also.

fauxtrot
+2  A: 

Is jQuery replacing JavaScript as a whole?

The only thing I never saw addressed in this thread was this: jQuery cannot replace Javascript,,, it is Javascript. It's nothing more than a collection of pre-written functions in Javascript that takes care of a lot of commonly-used and desired requirements of many developers.

Lets say you've always made your own paper (chop the wood, pulp it, dry it, decorate it, etc) before making your very special paper cut-outs. One day, while making paper cut-outs from your homemade paper, someone points out to you the wonders of pre-made paper (Oh happy day), and says "no need to make your own... get right to the fun of making paper cut-outs." You've never used pre-made paper... to you, paper is the result of a lot of time spent working with wood. So... now that you've discovered Acme Paper, would you ask if Acme Paper has replaced wood? Of course not... it's made from wood. Instead, you would suddenly think of Acme Paper as a time-saver, as a way to get to the final result of making cut-outs without all that wood-working hassle to make the paper itself.

Likewise, jQuery (the 'brand-name' paper) doesn't replace the Javascript (wood) from which it was made, it just saves you the hassle of making your own utility functions (paper) before you get to the fun of making your own custom code (little paper cutouts).

Have I confused the issue yet?

Cheers!

Lelando
+3  A: 

I think jQuery can't replace JavaScript for a very obvious reason. It's because jQuery doesn't solve a single problem in JavaScript - the language. It only solves problems with inconsistent DOM implementations between browsers which is its biggest strength and it comes with some syntactical sugar.

jQuery can't also replace the DOM APIs for another obvious reason. jQuery - the library, is controlled by one organization and primarily one man. DOM, on the other hand, is a spec that is implemented by tons of vendors while jQuery is merely a wrapper around the various implementations of that spec.

If jQuery were to replace these DOM APIs, then it will have to be a spec because different browser vendors can't just take its code and shove it in somewhere and make everything work nicely. The browser engine might be in C, C++, Java, or GolfScript so it becomes absolutely necessary for it to be a spec rather than an implementation.

Once jQuery API's become the de-facto standard and gets laid out in a spec, it will face the same problem that the specs face now. You can't just be a core-committer who fixes a problem overnight and releases a new version say 1.4.3 of the spec. The spec has be discussed, agreed upon, changed, released, and all implementors have to update their codebase to comply which makes the entire process slower. It also loses the ability to fix cross-browser quirks because it doesn't get to control that since its operating at a higher level in the food chain.

Then, because of it being a spec and moving slowly, you can always come up with your own library *Query that simplifies the spec APIs even further, fixes cross-browser issues, and move at a much faster pace.

This is why jQuery can't replace the DOM API because if it does, it will stagnate rather quickly as better, more innovative, and competing abstractions spring up every single day.

Anurag
+1  A: 

I've noticed the same thing lately. That jQuery - but take any other framework - destroys analytical thinking. Developers look at browser scripting as Duplo Lego when it's in fact Technics.

jQuery, while an excellent tool for UI manipulation - doesn't cover every aspect of high level JS programming. What about data, for instance? jQuery is quite poor in that area, but still, when a problem arises that has something to do with sorting or filtering - we go instantly into searching for a jQuery plugin.

jQuery will not, can not replace JS as a whole.

Dan Stocker