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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T17:16:06+00:00 2026-06-08T17:16:06+00:00

I try to get a function for an asynchronous recursion. In JS this should

  • 0

I try to get a function for an asynchronous recursion. In JS this should look like this:

(function asyncRecursion(){
  doStuff();

  setTimeout(asyncRecursion, 1000);
})();

Here’s what i’ve tried in CoffeeScript:

(asyncRecursion = ->
  doStuff()

  setTimeout asyncRecursion, 1000
)()

But this is compiled to:

(asyncRecursion = function(){
  doStuff();

  setTimeout(asyncRecursion, 1000);
})();

and i got an error in JSHint called ‘Bad invocation.’ for line 1, the asyncRecursion function.
So how can i get a JSHint safe asynchronous recursion function. The compiled version works, but there is still that JSHint error. Or should i ignore that ‘Bad invocation.’ error?

  • 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-08T17:16:09+00:00Added an answer on June 8, 2026 at 5:16 pm

    I think JSHint is confused. An assignment is an expression and the value of that expression is the assignment’s right hand side; that means that f = function() { ... } is an expression whose value is a function so (f = function() {...})() is perfectly valid JavaScript.

    If you ask JSHint about this:

    var f;
    (f = 11)();
    

    you’ll get the same “Bad invocation” error and we see that JSHint probably isn’t inferring the type of f, it just doesn’t want to you (f = x)() for any x (even when x is definitely a function). I’d tell JSHint to go pound sand and find a better tool. However, if you must use JSHint, you can write your CoffeeScript in two pieces:

    asyncRecursion = ->
      doStuff()
      setTimeout asyncRecursion, 1000
    asyncRecursion()
    

    and get this JavaScript:

    var asyncRecursion;
    asyncRecursion = function() {
      doStuff();
      return setTimeout(asyncRecursion, 1000);
    };
    asyncRecursion();
    

    which JSHint is happy with. Both your original and the “make JSHint happy” version produce the same result when executed.

    For extra fun with JSHint’s lack of type inference, ask it what it thinks of this:

    var asyncRecursion;
    asyncRecursion = 11;
    asyncRecursion();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I try to get this following url using the downloadURL function as follows: http://www.ncbi.nlm.nih.gov/nuccore/27884304
I am using the following function and code to try to get the size
When I try to call any GL15 function in lwjgl I get A NullPointerException.
I'm using YAHOO.util.Connect.asyncRequest to get data from database, here is the code : function
I try do get the locationServicesEnabled function to work... but my UIAlert shows up
In C++, if you try to get a function pointer of a Windows API
I did this function in PHP to get a page's title. I know it
Introduction I have a question coming from this one: Loop calling an asynchronous function
I have a problem here when I try to load these functions in this
When we try to create a view within a funcion we get ERROR: there

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.