Please Explain Internal Looping Under .each Docs #47

Closed
erikreppen opened this Issue Jul 18, 2012 · 4 comments

3 participants

@erikreppen

The internet groans and creaks under the weight of all the unnecessary .each methods out there. Something like this at the top of the .each docs

NOTE: Most built-in JQuery methods are applied to every element in a selector match. If you don't need to deal with elements on a case by case by case basis and just want to perform the same action on each one, you don't need to use the .each method.

@rwaldron
jQuery Foundation member

"JQuery methods are automatically applied to every element in a selector match

...

" The same is true of newly added JQuery object instance methods. You don't need to tell your new method to act on every element. The JQuery object handles that internally."

This is not correct. jQuery is a constructor with a prototype definition — when you call jQuery(selector), an instance is returned. "jQuery objects" are just instances of jQuery the constructor. When methods are added to jQuery.fn, they are being added to an alias of jQuery.prototype.

@erikreppen

Oh right. I was wondering how they pulled that off but the thing that lead me to that conclusion was just daisy-chaining a JQ method in the first place. *facepalm. I'll edit.

@erikreppen

I do still think it's worth adding to docs. People .each unnecessarily all the time.

@rwaldron
jQuery Foundation member

We could definitely add more about implicit iteration

@kswedberg kswedberg closed this in 20172f6 Sep 3, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment