Skip to content

Please Explain Internal Looping Under .each Docs #47

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Please Explain Internal Looping Under .each Docs #47

erikreppen opened this issue Jul 18, 2012 · 4 comments

Comments

@erikreppen
Copy link

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
Copy link
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
Copy link
Author

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
Copy link
Author

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

@rwaldron
Copy link
Member

We could definitely add more about implicit iteration

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

3 participants