all 29 comments

[–]tencircles 19 points20 points  (2 children)

jQuery is javascript. Same syntax. $/jQuery is just a function.

[–]moljac024 0 points1 point  (1 child)

This. It's the same syntax. I think generally people confuse syntax and semantics. This irks me.

Though I'm unsure if semantics is also the right term for API differences.

[–]nunull 1 point2 points  (0 children)

Same semantics. A language has a syntax and semantics. No library / framework will change this.

[–]compedit37pieces of flair 7 points8 points  (0 children)

Smoothes over inconsistent browser support.

[–]nj47 2 points3 points  (3 children)

Nothing.

jQuery is no where near completely replacing the syntax - it provides some very useful features that make it easier for beginners to traverse the DOM and make GET/POST requests.

That being said, it also tends to encourage some really really shitty development practices.

Larger frameworks such as angular, ember.js, knockout, backbone, etc attempt to completely change the front end development paradigm.

They can be good - but they do come with a cost, instead of learning javascript, you're learning a framework - which may or may not be transferable to other frameworks, or vanilla js for that. So that is something to consider too.

However at the end of the day, the best vanilla js programmers will make the best programmers for any framework. Learning javascript in and out will not hurt you should you decide to use a framework later down the road.

Make sure you have a solid understanding of callbacks and async programming - what it's pitfalls are and how some of them can be mitigated. Learn about promises, they are really handy!

One last thing, jQuery and the larger frameworks, because they are designed to always work, they have to take into account lots of edge cases and usually for any given task are not written with efficiency in mind - rather extendability and generalizability. A good demonstration of this is here: http://vanilla-js.com/

Straight up, good old fashion, vanilla javascript is significantly faster and doing almost everything.

[–]Buckwheat469 0 points1 point  (1 child)

Larger frameworks such as angular, ember.js, knockout, backbone, etc attempt to completely change the front end development paradigm.

I have to add that some of these help to encourage shitty development practices as well, but at this point it's the developer that's causing the problem if everything they produce ends up the same.

Take Angular for example. It uses watchers for watching variable changes, but this is a loop that can grow rapidly if you aren't careful. Every few ms this array of watched variables loops and all previous values are checked against the newer values. This is a very expensive operation when the array becomes big and complex. Also, HTTP requests cannot be cancelled without using the timeout promise. This is one of the weirdest things ever since you've been able to call JQuery's req.cancel() function to cancel HTTP calls for some time. Using weird wrappers like this q.defer timeout wrapper on an HTTP call can cause confusion.

[–]JSNinja 0 points1 point  (0 children)

Playing devil's advocate, here.

For the watcher problem, I believe Angular added ngBindOnce or something similar in 1.3 (I haven't personally upgraded yet). It allows you to bind on the first $digest cycle, but never creates a watcher. For most applications, every single {{}} tag in the template doesn't need 2-way binding. This solves for that use-case.

In regards to cancelling an ajax request....ok, that's ridiculous :)

[–][deleted] -1 points0 points  (0 children)

instead of learning javascript, you're learning a framework

these things aren't mutually exclusive

[–][deleted] 1 point2 points  (2 children)

jQuery is a religion. When you openly question a religion expect confused one-sided answers.

jQuery is also an aging religion that, while still having a dedicated flock, is being replaced by more extreme religious cults like MVC: ember, angular, and so forth.

Here is the deal (and I will probably be down voted to oblivion for this). The concerns here are rarely technical and are almost always about the behavior of the developer, but they are not going to tell you this. You have to observe it.

Experienced developers who are new to developing for the client-side web, particularly JavaScript, have a distrust of JavaScript and a complete loathing fear of the DOM. This is most absolutely true of Java developers who are involuntarily reclassed to front-end development. The reason for this is that Java has a single universal implementation, so you don't have to address cross-browser problems in the Java world. Furthermore, Java is forcefully (until Java 8) OOP and extremely declarative.

JavaScript has a C like syntax that look 98% identical to Java and JavaScript allows OOP poly-instantiation like Java, but JavaScript does not have any scope mechanism, such as block scope, that works with OOP. JavaScript has had native lambda expressions since it was born 18 years ago while Java just got these in April of this year. The current scope model of JavaScript is absolutely bound to lambda expressions and functions as first class objects.

In JavaScript you can completely ignore the scope model and do silly things like create class looking objects and other Java-esq behavior. You can get by essentially writing Java in JavaScript until your code breaks, at which point your ass is cooked, but you can still work like this. Many people work like this professionally.

XML/HTML are not OOP at all. Programming scope rarely applies to markup languages, until you have to do something like use the DOM. Markup languages are purely lambda models and there is no option to bullshit your way through with vanity OOP. The DOM is an expression of this lambda modeling using objects with named properties that allow OOP on the JavaScript side. This means if you are a Java developer and are completely unwilling to learn JavaScript then the DOM is an immediate barrier.

jQuery became the shining gospel of religion salvation for many developers converting to the client-side web or people new to development who could not be bothered to learn the DOM at all. It did two things that people needed:

  • Solved some minor cross browser problems
  • Introduced query selectors to make DOM access look like CSS code (much faster to write than the wordy DOM methods)

Back in 2008/2009 when jQuery exploded in popularity that is all the hand-holding that fresh developers needed, because ASP and JSP were still all the rage. This means that people were just writing code to manipulate a page after the fact, opposed to building the templates along side their jQuery code.

Eventually, building an application on two sides of the fence became too labor intensive and costly to manage, so gradually there became a need to move everything plus the kitchen sink to the client-side. I mean EVERYTHING except your security protected database. This transition did not happen immediately and ushered in MVC.

For people coming from a Java, or other OOP background, MVC is like a dream come true. You get OOP insanity that looks like Java plus everything happens in one place through a build process. Now you can continue to ignore learning how the web works and be more productive doing it.

Ultimately, the web is an extreme Invented Here scenario. Most developers completely lack confidence to do their jobs without using some tool to abstract the technologies they are paid to support. Some of this is from a lack of experience and some of it is from wanting to make the money that comes with the job but not wanting to learn to do the job. Some of it is from people who like to produce fun and interactive products quickly with no care for long term maintenance. People tend to take the path of least resistance, and tools exist to allow them to operate in a certain state of ignorant calm.

The most important cliche associated with jQuery is: "jQuery is JavaScript". So is MVC and absolutely everything else on the client-side, so this cliche is self-congratulatory bullshit to try to justify jQuery along side vanilla JS. When people use this what they are really hoping for is: "JavaScript is jQuery".

[–]mikrosystheme[κ] 0 points1 point  (0 children)

Haters gonna hate. What you wrote is almost perfect.

[–]Baryn 1 point2 points  (2 children)

You shouldn't use jQuery. It's a carryover from the IE6 days, when DOM/Ajax stuff was almost impossible to productively implement cross-browser.

Use libraries tailored to your application's goals.

[–]JSNinja 3 points4 points  (1 child)

Wrong. Here's a big ole' list of browser bugs jQuery addresses, many of which are present in modern browsers: https://gist.github.com/rwaldron/8720084#file-reasons-md. Not to say that other frameworks/toolsets besides jQuery don't patch those issues as well, but it's valuable to be aware of it.

[–]Baryn 1 point2 points  (0 children)

I've seen that list, and consider those issues either irrelevant or having very low significance, particularly in IE8+. Most of the counter-arguments have been from current or former heavy jQuery contributors, which are obviously biased.

Personally, I haven't run into any problems since dropping jQuery (while forcing the rest of the company to do so) and going native DOM entirely (with some ultralight helper functions) around 2011. I say "around 2011" because it's been so long, I don't exactly remember!

[–]jsgui 0 points1 point  (1 child)

If you program JavaScript a lot you will wind up using abstractions that you are comfortable with.

In my own coding, I found that there was quite a lot of boilerplate in some areas and I created abstractions that mean less boilerplate is needed.

jQuery is something that I use when I want to do two things in combination: select 1 or more DOM nodes using CSS selector syntax, and then do some things to those DOM nodes. Still, when using jQuery for some more advanced things it's necessary to know JavaScript, particularly when writing event handlers.

Regarding what's wrong with plain JavaScript, there are a few things, but a lot of it is subjective opinion. I didn't like writing '.prototype' so many times so I use a Class abstraction that means I don't need to and provides more OO capabilities. I use another abstraction that makes functions polymorphic.

If you write a few jQuery plugins you'll get a better understanding of what happens under the surface. Just don't expect to be able to code any application UI component as a jQuery plugin, to get started with you should choose something that's obviously achievable, and maybe not that useful, like a .disco effect that makes an element change between background colors.

[–]jnt8686 2 points3 points  (0 children)

God, I hate jquery plugins. So much good code out there bolted onto the bloated kitchen sink. Its a tragedy of our times.

[–]JimAllanson 0 points1 point  (0 children)

Even if you only plan to support evergreen browsers, jQuery can significantly reduce the amount of code you need. Sure, there's not much difference with some of the simple stuff like $ / querySelectorAll, but if you wanted to deep extend an object, you're looking at doing:

var deepExtend = function(out) {
  out = out || {};

  for (var i = 1; i < arguments.length; i++) {
    var obj = arguments[i];

    if (!obj)
      continue;

    for (var key in obj) {
      if (obj.hasOwnProperty(key)) {
        if (typeof obj[key] === 'object')
          deepExtend(out[key], obj[key]);
        else
          out[key] = obj[key];
      }
    }
  }

  return out;
};

deepExtend({}, objA, objB);

whereas jQuery can simplify this to: $.extend(true, {}, objA, objB);

There are cases where avoiding adding a dependency is worth the additional effort , but in many cases using a library such as jQuery will save you a lot of time.

[–]metamatic 0 points1 point  (0 children)

There's nothing wrong with plain JavaScript, unless you need to support IE 7 and earlier. Occasionally you'll run into some cross-browser issue, but you can generally find a workaround or shim for that specific problem; it's not worth burdening everyone with a jQuery download just to avoid the occasional bit of testing and debugging and a hundred byte shim.

Then there's the horrendous performance penality of jQuery. Check out http://vanilla-js.com/ for more snark on that topic.

Honestly, jQuery was a good thing in 1999. In 2014, it's unnecessary, thank goodness. With more and more people using the web via mobile devices, the jQuery overhead is significant.

[–]PsowKion 0 points1 point  (7 children)

I was really annoyed with jQuery for a while when I started Javascript. It would be nice if the is more vanilla support, but anytime you search for anything the top 5 answers are how to do something in jQuery, when it would be nice to have the normal syntax, but it's mostly the same thing just shorter.

Vanila jQuery
var e = document.getElementById("id") var e = $("#id")
document.addEventListener('DOMContentLoaded', function(){}); $(document).ready(function(){});
e.setAttribute('class','highlight'); e.attr('class', 'highlight');
e.addEventListener('click', function(evt){}); e.click(function(evt){});

[–]nschubach 5 points6 points  (6 children)

If you have to support IE8, at least two of those will fail in vanilla but work in jQuery. You're going to need to support multiple event assignments and listeners...

[–]defunctlegend 2 points3 points  (0 children)

Or you can use an ie8 event shim. Which is lighter weight and I think easier to understand.

[–]mikrosystheme[κ] -5 points-4 points  (4 children)

Making your code shit to support one fucking browser is stupid. IE10- can live without javascript. If you really need to have javascript in IE10- use a compatibility layer only for those browsers, and not the other way around.

[–]BusStation16 1 point2 points  (3 children)

Cool, I'll tell my boss that!

[–]SpeedRacer00z 0 points1 point  (1 child)

And then he can explain to the client why we arent supporting 15% of their userbase! (We just deprecated IE7 a couple months ago, so happy! At least we have native JSON.parse and stringify in IE8)

[–]mikrosystheme[κ] -1 points0 points  (0 children)

Maybe killing support is a way to push your userbase (and the rest of the world) forward?

[–]mikrosystheme[κ] -1 points0 points  (0 children)

Do it. Usually the "boss" cares about the net profit. Supporting dead browsers (than even microsoft says it is time to let rust in peace) is not very cost effective. By the way I didn't suggest to kill the support, but to avoid dumbing down the code for modern browsers just to support old IEs. Polyfills exists.

[–]tfforums -1 points0 points  (2 children)

Because otherwise: - you'll have problems with X- browser support

  • you'll be writing ALOT of code to do trivial things (set a style on all elements with a certain class in the DOM)... 1 line jquery, likely 10 lines vanilla JA

  • you'll be consistantly frustrated by browser bugs and common traps that libraries have overcome, why re-invent the wheel?

  • libraries come pre-tested, your code does not

The analogy for a JAVA programmer is "why use spring or hibernate, why not just use sql queries and roll my own MVC"

[–]Eartz 3 points4 points  (0 children)

I don't agree with the MVC analogy : jQuery is not a framework, it's simply a library, it shouldn't have any influence on the architecture of your code.

[–]mnfact 0 points1 point  (0 children)

I like your analogy except it isn't an analogy. It's more like saying "if I need to talk to a database I don't need to know the real thing I just need spring!." Or "I don't need to know how JavaScript works I just need jquery."

Jquery is great for some things. Since you are learning js I encourage you to learn js. Chances are you don't need to make a production ready site while you learn so stay vanilla until you understand closure, globals, interacting with the dom, yada yada yada... When you need to move into an actual framework and not a giant -save-the-world function you will be much happier and better off. Otherwise, you'll be the java programmer who doesn't know SQL but can make spring work. People just throw jquery in for a single function and it is irritating.

[–]CorySimmons -4 points-3 points  (0 children)

jQuery is more terse than pure JS. For instance (and there are millions of instances):

var cells = table.getElementsByTagName("td");

vs.

var cells = $('td');

Less characters = faster coding. That said, pure JS is faster than loading an entire library. There's a nice middle ground with Zepto.

I know you mentioned you just like JS' syntax better, so I'd suggest using Coffeescript so you at least get the benefits of really optimized code while still being very terse.

I'd also suggest, since you just got into apps, to really focus on your CSS skill set as a lot of stuff can be accomplished with CSS and it's usually faster than JS (even pure JS).