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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T21:49:55+00:00 2026-06-09T21:49:55+00:00

I am using a Javascript function do_when to keep evaluating another function and perform

  • 0

I am using a Javascript function do_when to keep evaluating another function and perform an action once it returns true. I found the function here: javascript, wait for something to be true then run action

Here is the do_when function:

function do_when(predicate, action, timeout_step) {
    if (predicate()) {
        action();
    } else {
        setTimeout(do_when, timeout_step, predicate, action, timeout_step);
    }
}

I am using it to call a jQuery function:

do_when(function() {return tabledrawn;},
    function() {$("#mytable tbody tr td").first().click();}, 
    100);

Everything works fine in Firefox and Chrome, but IE9 (and earlier) fails. Specifically, I get an “Object Expected” error when do_when is called from the setTimeout function.

When I do a debug, the predicate and action arguments correctly show up as function objects when do_when is initially called, but when it is called again from the setTimeout function they both show up as undefined. It appears I am not supplying the arguments to setTimeout the way IE wants to see them. Is there a proper way in IE to pass a function object and its parameters as arguments?

EDIT:
Per SLaks suggestions I changed do_when to the following:

function do_when(predicate, action, timeout_step) {
    if (predicate()) {
        action();
    } else {
        setTimeout(function () {
                       do_when(predicate, action, timeout_step);
                   }, 
                   timeout_step);
    }
}

Which fixes my problem.

  • 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-09T21:49:57+00:00Added an answer on June 9, 2026 at 9:49 pm

    You’re passing additional arguments to setTimeout, and you’re expecting them to be passed to your function.

    That’s a non-standard Mozilla-only feature.

    Instead, you need to pass an anonymous function to setTimeout, and call your function with whatever arguments you want inside of it.

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

Sidebar

Related Questions

I call a javascript function from a textbox by using OnKeyPress=clickSearchButton() Here is my
Using the javascript function function squareIt(number) { return number * number; } When given
I'm using a javascript function to submit my form. This works in every browser
I am using this JavaScript function in order to change image on click, but
I am having trouble using a javascript function in my wp7 application. I am
I have a canvas that I am using a javascript function to display text
I am using JavaScript's replace() function to replace a regular expression matching A-Z, a-z,
I am having issues passing a dynamic parameter to a JavaScript function using innerHTML.
Using javascript I'm looping through my H3 elements like this: $('h3').each(function(){ }); I'm then
I wish to execute a javascript function after asp.net postback with out using ajax.

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.