0

I have the following JS code

$(document).ready(function(){
  update_items();
  adjust_size_of_menu();
});

var adjust_size_of_menu = function() {
  // global boolean set in update_items_count();
  if ( !items_updated ) 
  {
     alert("Treatment of update_items() not done yet");
     setTimeOut( function(){ adjust_size_of_menu(); }, 1000);
  }
  // More treatment goes here 
}

As you can see, I am setting a variable in the first function. This variable must be true before I proceed with the execution of the rest of the instructions in the second function.

The problem here is that the first time I go into adjust_size_of_menu(), it shows me the alert, which is fine. After that, it should wait 1 second then re-execute the adjust_size_of_menu() from the beginning until the item_updated boolean is true, then we continue with the rest of the code.

What is the problem with this code? I've already used the same approach elsewhere and worked just fine.

1
  • 4
    It should be setTimeout()--you've capitalized it incorrectly. Commented Sep 10, 2015 at 20:41

2 Answers 2

2

setTimeOut is not a built-in function in javascript. If you've used it elsewhere, it's because you or someone else declared it. The correct spelling is setTimeout. Note the lowercase "o".

https://developer.mozilla.org/en-US/docs/Web/API/WindowTimers/setTimeout

Sign up to request clarification or add additional context in comments.

1 Comment

That was the problem ! The search was not case sensitive and it was showing me the other setTimeout even if i was looking for setTimeOut...
1

javascript is case sensitive language and it should be setTimeout()

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.