On Jul 19, 6:25 am, Chris Ahn <[EMAIL PROTECTED]> wrote:
>
> [snip]
>
> Why the "setTimeout(function() {html.evalScripts()}, 10);" is used?
> Why do not directly do "html.evalScripts()"? What's the intention and
> benefits of using that technique?
>
> Thanks in advance!Well, there may be many reasons to use setTimeout in a chain of execution. As I understand it, here are some of them : 1) Javascript is a single threaded language, which means that the browser will "hang" as long as there are functions being called in the stack of events. Then, since eval() does not return until the string is interpreted, using setTimeout will give the browser some time to respond to events. 2) To prevent infinite loops or non responsive scripts, browsers will implement a timeout warning that will let the user "stop" it's execution so the browser may respond to events again. Thus, using setTimeout between calls of time consuming functions will keep the browser from popping up that warning. 3) When updating the DOM, some browsers requires some time to apply the changes made to the document tree, and this will not happen while some script is executed. Therefore, setTimeout, even for 10 milliseconds, will give the browser enough time to do so, then come back to script execution. The function eval() is a time consuming function, so it's execution is better executed separatly. Then again, setTimeout should not be used at large (like any other tweaks and tricks) as it delsys execution of functions. Anyway, some people will probably explain this better than I do, but I think this sums up the most of it. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
