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 8224939
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T15:14:38+00:00 2026-06-07T15:14:38+00:00

I was examining one of my client’s code and came across this. $(document).ready(function() {

  • 0

I was examining one of my client’s code and came across this.

$(document).ready(function() {
    function foo1() {
        $("#id1").bind('click', function() {});
    }
    foo1();

    function foo2() {
        $("#id2").bind('click', function() {});
    }
    foo2();
});

What they are doing is, attaching event handler inside the function and then calling that function.

How does it differ from the following?

$(document).ready(function() {
    $("#id1").bind('click', function() {});
    $("#id2").bind('click', function() {});
});

That is attaching event handlers directly in $(document).ready() function.

It works fine in both the scenarios, I was just wondering if there are some performance related issues or something. Like one works faster or slower. Or is it a standard way of doing things which I am not aware of.

  • 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-07T15:14:39+00:00Added an answer on June 7, 2026 at 3:14 pm

    The difference it you can re-use that part of your code to call foo2() at any place in your code again instead of copy the whole code.

    EDIT:

    Let me give you an example

    On failure it needs to show an alert with ‘Hello, that was going wrong!’ you can do these two things:

    alert('Hello, that was going wrong!');
    

    or

    function showError() {
    alert('Hello, that was going wrong!');
    } 
    showError();
    

    Solution 1 seems to be the easiest one.

    But….. Imagine you are working on a really large project with places to show that error on 1000 places. Now you need to edit your message at 1000 places instead of just one place.

    Or when you want to show an HTML popup instead of an alert, imagine changing that.

    Hopes the explanation it makes sense, when not please let me know.

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

Sidebar

Related Questions

I am examining a core dump, and noticed that in one frame the 'this'
I've been examining one of my c# books and I just saw a sentence
Examining the compiled code of the sinf() on our GCC implementation, I see that
So, examining this directory structure /include_one.php /include_two.php /directory/main_file.php Assume that I am in /directory/main_file.php
I'm using Zend_View to template text email content. However, I've come across one problem
Not sure where to start on this one -- not sure if the problem
this is not a question about a specific programming problem, it's about examining different
I'm examining the GNU GRUB source code and in /grub-core/boot/i386/pc/*.S files, there are a
I am examining a js file form Bram Jetten: Notification.fn = Notification.prototype; function Notification(value,
Examining bytecode, I've noticed javac seems to duplicate checkcast instructions when casting to array

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.