Live data from Hacker News

You Don't Need JQuery

blog.garstasio.com

91–100 of 201 posts

Re: You Don't Need JQuery

#91
post #23

Earlier quoted context omitted.

`$(".foo").removeClass("bold")` becomes the wonderfully concise [].map.call(document.querySelectorAll(".foo"), function(node) { node.classlist.remove("bold"); })

This may seem anecdotal, but I can tell you from writing a lot of non-jQueryified code that with modern browsers, applying classes to dozens of elements dynamically can be an anti-pattern. 99% of the time, when doing something which previously would have required that, I can use a single class on a parent element.

No, you're going to mess with repaints and renders. It is not an anti pattern.

Re: You Don't Need JQuery

#92
post #14
post #7

You can basically sum up this entire rather ridiculous site with "Yes, you don't need jQuery, you can just use the built-in methods, but using jQuery is generally more pleasant, more consistent, and involves less typing". One particularly egregious example from the site: $('#foo').removeClass('bold'); vs. document.getElementById('foo').className = document.getElementById('foo').className.replace(/^bold$/, ''); The au…

document.getElementById('foo').classList.remove('bold'); see https://developer.mozilla.org/en-US/docs/Web/API/Element.cla...

If I saw that, first comment on the PR would be to wrap that eye sore in a wrapper function with a clear name. Which is basically what jQuery is doing.

Re: You Don't Need JQuery

#93
post #56

Earlier quoted context omitted.

.classlist() [1] is coming [2]. It'll allow you to do: document.getElementById('foo').classList.remove("bold"); Sure, it's still more verbose. But a lot of what jQuery does is slowly being obsoleted by better native javascript apis. [1] https://developer.mozilla.org/en-US/docs/Web/API/Element.cla... [2] http://caniuse.com/#feat=classlist

before jQuery I always defined an ID method like: function ID(id) { return document.getElementById(id); } saved some typing. I'll always try to use jQuery now though, bigger problems to solve.. few extra bytes to download is not that bad...

[deleted]

Re: You Don't Need JQuery

#95
You don't need jQuery if you have written better wrapped API library and have already attracted millions of developer to test your library.

For the eco-system point of view, jQuery have been tested in the widest markets for many many years. well written document, many online cases, many supporters, many bug reporters, high cover unit tests,good code quality and so on.

Using jQuery for project is smart move unless high performance requirement.

Re: You Don't Need JQuery

#96
post #35

Yeah, you don't need anything. You can write all your apps in vanilla JS, but if you feel like speeding up development...

and slowing down your website

jQuery is usually cached in your browser because of how common it is. From what I understand, the slowing is negligible. Part of a developer's role is to mitigate site performance with the speed of process. Inlining of critical CSS is one way to balance out initial page load, for example.

Re: You Don't Need JQuery

#97
post #26

Earlier quoted context omitted.

.classlist() [1] is coming [2]. It'll allow you to do: document.getElementById('foo').classList.remove("bold"); Sure, it's still more verbose. But a lot of what jQuery does is slowly being obsoleted by better native javascript apis. [1] https://developer.mozilla.org/en-US/docs/Web/API/Element.cla... [2] http://caniuse.com/#feat=classlist

So when those new native api functions arrive, jQuery will start using them and gain some performance boost (using native vs. custom js code) while at the same time remaining backwards compatible (by doing feature detection). No one wants to write their own feature detection code so this whole page about using native apis is instead of jQuery is ridiculous. If the point of that website was to educate people on the ap…

This a thousand times, I know with $.trim it will use trim() for good browsers and then whatever hack effort was necessary for IE8. It would be devastating to have to write this manually.

Re: You Don't Need JQuery

#98
post #7

You can basically sum up this entire rather ridiculous site with "Yes, you don't need jQuery, you can just use the built-in methods, but using jQuery is generally more pleasant, more consistent, and involves less typing". One particularly egregious example from the site: $('#foo').removeClass('bold'); vs. document.getElementById('foo').className = document.getElementById('foo').className.replace(/^bold$/, ''); The au…

Actually since forever, you don't need to use document.getElementById("x") in any case. You just by putting the id to the element, it is already available to you referencing it by such id.

So this:

    document.getElementById('foo').className = 
          document.getElementById('foo').className.replace(/^bold$/, '');
Can become to this:

    foo.classList.remove("x");
And is miles away more performant than slow jQuery.

Re: You Don't Need JQuery

#99
post #20

Lots of blanket statements in this article. He asserts there is a 'proper' order to learning JavaScript but makes no demonstration of that assertion. For me, jQuery was a gateway that hid much of the incidental complexity of working with a byzantine API (the dom). That was incredibly useful. If every beginner started with trying to understand the DOM, they'd probably be scared off (and rightly so).

What you call Byzantine, I call normal. Some things are harder to learn than others but you can't throw your hands up in the air and let someone else (jQuery) do the simple things for you. Working with the DOM is what we programmers do. I've never seen so many people complain so much about programming than those who use jQuery.

The DOM strikes as being composed of layers of incidental complexity that get in the way of the actual problem you're trying to solve. jQuery, or abstractions like it, allow us to compose more elegant and semantically meaningful solutions to problems. If writing boilerplate is interesting for some reason, be it for performance reasons perhaps, then by all means. I find it a bit tedious and appreciate tools that allow me to focus on the problems at hand, rather than obscure browser differences and internal API implementation inconsistencies.

Re: You Don't Need JQuery

#100
post #14
post #7

You can basically sum up this entire rather ridiculous site with "Yes, you don't need jQuery, you can just use the built-in methods, but using jQuery is generally more pleasant, more consistent, and involves less typing". One particularly egregious example from the site: $('#foo').removeClass('bold'); vs. document.getElementById('foo').className = document.getElementById('foo').className.replace(/^bold$/, ''); The au…

document.getElementById('foo').classList.remove('bold'); see https://developer.mozilla.org/en-US/docs/Web/API/Element.cla...

Unless it turns out there's no `foo` in the page, then that blows up.
Post reply on HN