Learn JavaScript asynchronous Programming continuous update

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.