var start = new Date;
SetTimeout (function () {
var end = new Date;
console.log (' end~~~ ', End-start, ' Ms ');
},0);
while (new Date-start < 4000) {
if (new Date-start = = 3999) console.log (' End ')
}
Start timing after running settimeout, and put the callback function at the end of the delay event queue.
After all the synchronous JS events are completed, the settimeout callback function is executed, even if the SetTimeout setting event is less than the event run by the synchronization event, the synchronization event is not executed, and the settimeout callback function is not executed
------------------------------------------
<div id= "click" >aaa</div>
<script>
window.onload=function () {
document.getElementById (' click '). Onclick=function () {
console.log (' You clicked the Click ');
}
var start = new Date;
while (new Date-start < 1000) {}
}
</script>
When the page is loaded, after clicking Id#click, JS will put the current click on the event into the queue, and so on after the synchronization of JS execution to perform the OnClick event.
-----------------------------------------
Not to be continued
Article Source: http://my.oschina.net/edire/blog/347702
Learn JavaScript asynchronous Programming continuous update