Live data from Hacker News

JQuery 1.8b1: what’s new?

blog.jquery.com

41–48 of 48 posts

Re: JQuery 1.8b1: what’s new?

#41

Earlier quoted context omitted.

I'm just curious what the higher-level APIs are that people need from jQuery that aren't available on mobile. I recall jQuery being popular for selector queries (available on all mobile browsers natively with querySelector and querySelectorAll) and for even listeners (offers no real advantage over addEventListener as far as I can tell).

Well one nice affordance jQuery offers, is you can do manipulations en-mass without having to write out a loop, or use Array.forEach(). This helps simplify event binding and manipulation code. Also there are selectors in jQuery that are not available in querySelectorAll. And lastly querySelectorAll has some pretty buggy implementations. jQuery smoothes these out.

Binding event handlers in a loop is an anti-pattern greatly promoted by jQuery during several years. You should use event delegation.

Re: JQuery 1.8b1: what’s new?

#42
post #41

Earlier quoted context omitted.

Well one nice affordance jQuery offers, is you can do manipulations en-mass without having to write out a loop, or use Array.forEach(). This helps simplify event binding and manipulation code. Also there are selectors in jQuery that are not available in querySelectorAll. And lastly querySelectorAll has some pretty buggy implementations. jQuery smoothes these out.

Binding event handlers in a loop is an anti-pattern greatly promoted by jQuery during several years. You should use event delegation.

Sure but $('.clicky').on('click', doSomething); means no loops at all, and will bind events to all matching elements. I don't think there is a native API way to do this.

Edit: typos

Re: JQuery 1.8b1: what’s new?

#43
post #41

Earlier quoted context omitted.

Binding event handlers in a loop is an anti-pattern greatly promoted by jQuery during several years. You should use event delegation.

Sure but $('.clicky').on('click', doSomething); means no loops at all, and will bind events to all matching elements. I don't think there is a native API way to do this. Edit: typos

document.getElementsByClassName('clicky').forEach(function(el) { el.addEventListener('click', doSomething); });

Re: JQuery 1.8b1: what’s new?

#44
post #41

Earlier quoted context omitted.

Binding event handlers in a loop is an anti-pattern greatly promoted by jQuery during several years. You should use event delegation.

Sure but $('.clicky').on('click', doSomething); means no loops at all, and will bind events to all matching elements. I don't think there is a native API way to do this. Edit: typos

As far as I know jQuery is written with "native API", so there is obviously a way to do this in JavaScript.

    document.body.addEventListener("click", function(e) { 
      if (e.target.className == "clicky") {
        doSomething();
      }
    }, false);

Re: JQuery 1.8b1: what’s new?

#45

Earlier quoted context omitted.

Sure but $('.clicky').on('click', doSomething); means no loops at all, and will bind events to all matching elements. I don't think there is a native API way to do this. Edit: typos

document.getElementsByClassName('clicky').forEach(function(el) { el.addEventListener('click', doSomething); });

I'm not sure that works. getElementsByClassName (and Id and querySelector) returns a NodeList, not an Array, so there's no foreach, you have to convert it to an array first.

Re: JQuery 1.8b1: what’s new?

#46
post #45

Earlier quoted context omitted.

document.getElementsByClassName('clicky').forEach(function(el) { el.addEventListener('click', doSomething); });

I'm not sure that works. getElementsByClassName (and Id and querySelector) returns a NodeList, not an Array, so there's no foreach, you have to convert it to an array first.

Array.prototype.slice.call(document.getElementsBy....

Re: JQuery 1.8b1: what’s new?

#47

"jQuery is now powering about one-half of all the major web sites on the Internet" Anybody have any data on this?

Few of them are major, but the worlds most popular CMS, Joomla, runs 2-3% of all websites, and they will be switching to jQuery (from mootools) later this year.

What data do you have that supports that Joomla is the world's most popular CMS?

Re: JQuery 1.8b1: what’s new?

#48
post #45

Earlier quoted context omitted.

I'm not sure that works. getElementsByClassName (and Id and querySelector) returns a NodeList, not an Array, so there's no foreach, you have to convert it to an array first.

Array.prototype.slice.call(document.getElementsBy....

That's also a ton of tying and a lot of code that a minifier can't reduce. I guess its possible, but do you really want to writing such verbose code?
Post reply on HN