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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T08:17:58+00:00 2026-06-18T08:17:58+00:00

new Something({ events:{ load: (function loopsiloop(){ console.log(this); // firstime this will be Something, but

  • 0
new Something({
    events:{
        load: (function loopsiloop(){

            console.log(this);  // firstime this will be Something, but next call what its

            setTimeout(function(){
                console.log(this);
                $.ajax({
                    url: 'foo.htm',
                    context: this,
                    success: function( response ){
                        // do something with the response
                    },
                    error: function(){
                        // do some error handling.  you
                        // should probably adjust the timeout
                        // here.
                    },
                    complete: function(){
                        loopsiloop(); // recurse  //need to bind this here like loopsiloop().bind(this)
                    }
                });
            }.bind(this), 5000);
        }),
        click: function(){
            alert("clicked");
        }
    }

})

Please go through the code and read comments, here the problem is i need to use this in setTimeOut function, so I am binding this to setTimeOut, but when I am calling function as recursive the value of this will not be same

NB:- I dont want to pass the object to the function and dont want to use setIntervel (http://www.erichynds.com/javascript/a-recursive-settimeout-pattern/)

  • 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-18T08:17:59+00:00Added an answer on June 18, 2026 at 8:17 am

    Your recursive call can be written like this:

    complete: function() {
        loopsiloop.call(this);
    }
    

    to ensure that the context is correctly set the second time around.

    It could also be written like this, but it’s not recommended as it’ll call .bind over and over on each pass:

    complete: loopsiloop().bind(this)  // NB: no function wrap, just passes the ref
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When you have code like this: Something something = new Something(); BlahEntities b =
maybe it's dumb but is there a difference between new Something().method(); and Something tmpSomething
I am successfully loading content through the use of jQuery(.menu li a).click( function(event){ jQuery(#loadingArea).load(this.href)
I'm new to Telerik MVC controls, so this may be something simple. I started
I'm new to event programming, and I'm obviously misunderstanding something that I'm trying to
Is there something new about row-level security in SQL Server 2012? In 2008 and
When saving a new entity something strange happens... I have a data grid with
I am trying something new and I am having issues with my current idea.
I'm trying something new and trying to run before I can crawl. I'm using
I'm faced a new problem something with memory allocation and leak here is my

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.