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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T03:23:15+00:00 2026-05-15T03:23:15+00:00

In the application I’m building I’m polling for a status update and I have

  • 0

In the application I’m building I’m polling for a status update and I have noticed that if the call is made as follows the timeout fires continuously:

setTimeout($.get("http://localhost:8080/status", function(data) { UpdateStatus(data);}), 1000);

While if use a function instead the timeout fires every 1000 ms:

 setTimeout(function() {$.get("http://localhost:8080/status", function(data) { UpdateStatus(data);})}, 1000);

Why?

  • 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-15T03:23:15+00:00Added an answer on May 15, 2026 at 3:23 am

    In the first example, you’re calling $.get and then passing its return value into setTimeout. In the second example, you’re not calling the function at all; you’re giving setTimeout a function that it will call later, which will then call $.get for you.

    This is easier to see with a simpler test case:

    function test() {
        alert("Hi there!");
    }
    
    // WRONG, *calls* `test` immediately, passes its return value to `setTimeout`:
    setTimeout(test(), 1000);
    
    // Right, passes a reference to `test` to `setTimeout`
    setTimeout(test, 1000);
    

    Note that the first one has parentheses (()), the second one doesn’t.

    When you want to pass parameters to the function, you have to do it indirectly by defining another function:

    function test(msg) {
        alert(msg);
    }
    
    // WRONG, *calls* `test` immediately, passes its return value to `setTimeout`:
    setTimeout(test("Hi there!"), 1000);
    
    // Right, passes a reference to a function (that will call `test` when called) to `setTimeout`
    setTimeout(function() { test("Hi there!"); }, 1000);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

application design/architecture question for a project that I am building. I have a main
Application use NHibernate. I Have object A that contains set of objects B. I
Application : HTA (therefore IE) This is an application that uses SendKeys to populate
Application launch through Java web start(JWS) checks for update when we are launching it.
An application I have recently started work on has to register two dll's, because
The application I'm currently writing is using MVVM with the ViewModel-first pattern. I have
my application use 10 threads that to read a lot of html file.similar the
Application uses Entity Framework 4.1 with database first approach. I have in database a
Application.Run(form); Actually I tried to call this from my project. I got this exception.
My application is having two activities. In first activity, I have one button and

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.