Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8359111
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T11:02:24+00:00 2026-06-09T11:02:24+00:00

Just a small theoretical performance question: if I have something like: $(.somediv).each(function() { //

  • 0

Just a small theoretical performance question:

if I have something like:

$(".somediv").each(function() {
   // perform some heavy stuff here
});

Would the execution of the code not be faster if I refactored the code of the anonymous function to a named function like :

f = function() {
   // perform some heavy stuff here
};

$(".somediv").each(f);

Somehow I have this irrational doubt that tells me that perhaps the anonymous function is re-created each time within the each loop?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T11:02:26+00:00Added an answer on June 9, 2026 at 11:02 am

    If you are concerned about performance, then you should not use .each(). It is much faster to iterate the contents of a collection with a for loop or a while loop and have no function call at all than it is to use .each() with its resulting function call for each item.

    In answer to your question, the anonymous function will not be any slower than the named function. The differences are resolved at parse time before run-time.

    This jsPerf shows a plain for loop as almost 10x faster than .each(): http://jsperf.com/each-vs-for-loop-mine.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Just a small question regarding joins. I have a table with around 30 fields
I'm learning JavaFX and this is just a small programming question. I have 3
I have written a small program just like hello the world , everything was
$(#infoBox).hide(, function(){ alert('hidden!'); }); Just a small question, but my code breaks when I
Just a small question. Say I have the following HTML: <div class=foo> {text} </div>
Just a small question about c++/cli. Abstract classes have abstract methods to be implemented
Just a small question I can't find an answer to. If I add a
Just tried some small graphics application of mine on Windows 7, and I'm getting
I have just written a small piece of code and it struck me that
I've just created a small js framework like underscoer.js. The method calls are carried

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.