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

  • SEARCH
  • Home
  • 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 7810191
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T03:40:51+00:00 2026-06-02T03:40:51+00:00

What is the difference/advantages of using the $(docu…) with your variables and functions defined

  • 0

What is the difference/advantages of using the $(docu…) with your variables and functions defined inside, from using it with a function and then calling it inside the $(docu…)

$(document).ready(function (){
    initialize();
});
function initialize(){
    hello
}

over using this:

$(document).ready(function (){
        hello
});
  • 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-02T03:40:53+00:00Added an answer on June 2, 2026 at 3:40 am

    These four options all create exactly the same result with declining flexibility:

    Example #1

    $(document).ready(function (){
        initialize();
    });
    
    function initialize(){
        hello();
    }
    

    Example #2

    $(document).ready(initialize);
    
    function initialize(){
        hello();
    }
    

    Example #3

    $(document).ready(function (){
            hello();
    });
    

    Example #4

    $(document).ready(hello);
    

    In the first example, you are creating an anonymous function that will be called at document.ready time. That anonymous function calls a separate function initialize(). Because initialize() is a separate function, it could also be called by other code.

    In the second example, you just avoid the anonymous function and pass a reference to the initialize function directly. This works slightly faster than the first example (one less function call), but is less flexible if you wanted to call more than one function besides initialize() from the document.ready() handler.

    In the third example, you just remove the outer initialize() function and just call the one thing inside it that it was doing from an anonymous function.

    In the fourth example, the anonymous function is again removed and you just pass a direct reference to the hello function so it will be called directly without any intervening functions.

    The first option gives you the most flexibility because you can call multiple things inside of initialize() and you can also call initialize() from other places in your program. If you don’t need those flexibilities, you can pick any one of the other four options as they all produce the same results, each with a little less flexibility.

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

Sidebar

Related Questions

Possible Duplicate: String, StringBuffer, and StringBuilder what is the difference (advantages, disadvantages) between using
What is the difference between using view templates in Rails as '.html.haml' and as
I'm using cygwin-git locally inside a CVS repository on Windows at my workplace, in
Possible Duplicate: Using Memcache vs Memcached with PHP Someone can explain me the difference
What is the difference in using AbstractWizardFormController OR Spring Webflow. How should one decide
I was just wondering what were the advantages and disadvantages of using System.out.printf(); We
What's the difference when using GET or POST method? Which one is more secure?
What is the difference between using this [self performSelectorOnMainThread:@selector(doStuff:) withObject:myObject waitUntilDone:YES]; instead of simply
Like in question, i don't get what is the difference between using those classes.
what is the difference / advantage of using PDOStatement instead of regular Mysql?

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.