0

The SO question (load-and-execution-sequence-of-a-web-page)gives details into the order of execution of html page. It states - that the script tag is executed sequentially with single thread.

I have the following code on my page:

if(booleanTest)eval('parent.'+callback+'();');
     parent.hideWin();
     return false;

Assuming that the callback method is having a simple while loop that ran for a large number of times (eg : 30K times), I noticed that the hideWin was getting executed even before the callback even completed.(Tested on IE7)

The point is - if the execution is sequential then why is the above behavior in place - is it something specific to browser?.

Community
  • 1
  • 1
techzen
  • 2,895
  • 2
  • 22
  • 22
  • How are you sure callback is done executing? Perhaps the browser is trying to optimize a large number of UI operations and delaying re-rendering some of the effects of the callback and the hideWin call gets lumped in with some iterations? – Yuliy Jan 07 '10 at 07:03
  • 2
    Note you rarely need `eval`. In this case, you can use the fact that object properties can be accessed using string keys: `if (booleanTest) { parent[callback](); }`. If `callback` isn't in fact a string naming a method defined on `parent`, then the reason `parent.hideWin()` is executing so quickly is that the `eval`-ed script is failing. – outis Jan 07 '10 at 07:05
  • 1
    +1 for getting rid of evals for property access that were common in 1995, I'm amazed that people still write this nowadays – Ruan Mendes Nov 23 '10 at 19:14

1 Answers1

0

yeah, the second line will execute only after the if+eval. i would do an alert before hidewin to check if booleanTest and any other state is the expected vals

jspcal
  • 50,847
  • 7
  • 72
  • 76