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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T15:01:50+00:00 2026-05-16T15:01:50+00:00

Now, I usually call a function (that requires no arguments) with () like this:

  • 0

Now, I usually call a function (that requires no arguments) with () like this:

myFunction(); //there's empty parens

Except in jQuery calls where I can get away with:

$('#foo').bind('click', myFunction); //no parens

Fine. But recently I saw this comment here on SO:

“Consider using setTimeout(monitor, 100); instead of setTimeout('monitor()', 100);. Eval is evil :)”

Yikes! Are we really eval()-ing a string here? I guess I don’t really understand the significance and implications of ‘calling’ a function. What are the real rules about calling and referring to functions?

  • 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-05-16T15:01:50+00:00Added an answer on May 16, 2026 at 3:01 pm

    In JavaScript functions are first-class objects. That means you can pass functions around as parameters to a function, or treat them as variables in general.

    Let’s say we are talking about a function hello,

    function hello() {
        alert('yo');
    }
    

    When we simply write

    hello
    

    we are referring to the function which doesn’t execute it’s contents. But when we add the parens () after the function name,

    hello()
    

    then we are actually calling the function which will alert “yo” on the screen.

    The bind method in jQuery accepts the type of event (string) and a function as its arguments. In your example, you are passing the type – “click” and the actual function as an argument.

    Have you seen Inception? Consider this contrived example which might make things clearer. Since functions are first-class objects in JavaScript, we can pass and return a function from within a function. So let’s create a function that returns a function when invoked, and the returned function also returns another function when invoked.

    function reality() {
        return function() {
            return function() {
                alert('in a Limbo');
            }
        };
    }
    

    Here reality is a function, reality() is a function, and reality()() is a function as well. However reality()()() is not a function, but simply undefined as we are not returning a function (we aren’t returning anything) from the innermost function.

    So for the reality function example, you could have passed any of the following to jQuery’s bind.

    $('#foo').bind('click', reality);
    $('#foo').bind('click', reality());
    $('#foo').bind('click', reality()());
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Now that LINQ to SQL is a little more mature, I'd like to know
Now that it's clear what a metaclass is , there is an associated concept
Almost all of the examples in the jQuery tutorials that I've read, usually use
I usually write C# programs for myself, or just parts of other applications. Now,
Now that most of the major browsers support full page zoom (at present, the
Now that I know C++ I want to get into desktop application that have
Now that .NET v3.5 SP1 has been released (along with VS2008 SP1), we now
Now this is .NET but I am sure the principal should apply to all
Now, I know this is completely subjective, so please don't flame me. I've never
A nasty gotcha in javascript is forgetting to call new on a function meant

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.