M
morgan.chengmo
Hi,
I am wandering whether all javascript code in one page is executed in
one thread. I know that javascript has no threading mechansim. No way
to tell which thread is running by code iteself.
For below code
<html>
<head>
</head>
<body>
<script type="text/javascript">
function onTimeout()
{
alert("time out");
}
setTimeout("onTimeout()", 5000);
while (true)
{
}
</script>
</body>
</html>
If there is only one thread and event loop, I suppose the script will
end in dead loop. But, in IE, the alert pops up after 5 seconds. How to
explain it?
Does each browser page has only one thread interpreting script?
Thanks,
I am wandering whether all javascript code in one page is executed in
one thread. I know that javascript has no threading mechansim. No way
to tell which thread is running by code iteself.
For below code
<html>
<head>
</head>
<body>
<script type="text/javascript">
function onTimeout()
{
alert("time out");
}
setTimeout("onTimeout()", 5000);
while (true)
{
}
</script>
</body>
</html>
If there is only one thread and event loop, I suppose the script will
end in dead loop. But, in IE, the alert pops up after 5 seconds. How to
explain it?
Does each browser page has only one thread interpreting script?
Thanks,