"Thomas 'PointedEars' Lahn" <> schreef in bericht
news:...
> Tom de Neef wrote:
>
>> Two customers, using W7 and IE, report that my app does not repond to
>> certain menu commands. No other users seem to have a problem.
>
> Your problem is likely caused by how many times setMenuTimer() is called,
> as
> intervals would accumulate if it is called more than one time.
> window.setInterval() is almost always inferior to a self-calling
> window.setTimeout().
>
>> My code has a statement in <script type="text/javascript">:
>> function setMenuTimer(){
>> if (currentMenuIndx==0) {return};
>> if (menuTimerSet>0) {clearInterval(menuTimerID)};
>
> You should not rely on this test; there is nothing that says that
> setInterval() cannot return 0, or values less than 0. Instead, initialize
> the timer variable with a value that is rather unlikely to be returned by
> window.setInterval(), such as `null', and compare against that. After
> window.clearInterval(), always reset the variable value.
You may have missed that I used menuTimerSet (0 or 1) for the test and
menuTimerID for the return value of the setInterval call.
I think that was the correct way of doing it, but I liked your approach
better, using 'null' and avoiding the need for the test variable.
>
>> menuTimerID = setInterval(exitMenu,1500); //<<< A
>> menuTimerSet = 1
>> }
>>
>> menuTimerID, menuTimerSet and currentMenuIndx are declared, exitMenu is a
>> function.
>
> No, it is the name in a function declaration, or the name in a variable
> declaration for a variable that is later assigned a function reference; so
> it is a function *reference*. Functions are first-class objects in-
> ECMAScript implementations. Objects need be referred to.
Always a pleasure to read your formal corrections. I learn from it but I
fear I'm too old to catch up.
>> I am confused by the setInterval call (A).
>> exitMenu is a function and I have now changed the code to
>> menuTimerID = setInterval("exitMenu()",1500); //<<< B
>>
>> On my system, both implementations seem to work (and have the desired
>> effect of hiding the menu drop down awhile after the cursor moves out -
>> it). Questions:
>> - is statement A valid? It doesn't throw an error, but should it actually
>> call the function exitMenu?
>> [.]
>> - is statement B the correct way to call setInterval?
>
> Yes, and it depends (`exitMenu' has to be global for the latter to work).
> It should be window.setInterval(.), though.
Yes.
Thank you and Richard C and Dr S.
I have moved from window.setInterval to window.setTimeout. The code is
relatively simple and I am sure that setTimeout will not be called during
its own wait period.
When I step through the code at the client side (using W7 RemoteHelp)
evrything works fine. But letting the code run freely leads to
irreponsiveness (with this customer only).
There must be another timing issue - outside my own code - to do with Ajax
calls to the server. I think that my worry about setInterval has been a red
herring.
Tom de Neef
|