Compile the JS engine to provide sleep for JavaScript ).

Source: Internet
Author: User
Tags sleep function
Author: failingProgramMember-eight gods Does JS have sleep functions ?, Yes, we add it ourselves.

How many seconds does function sleep in JS? This problem is often raised by beginners of JavaScript, since the emergence of JavaScript.

That's why this function is not provided in Js?

Currently, all browsers parse Js in the UI thread. Taking Firefox as an example, I re-compiled the JS engine and added the sleep method to the JS alert. This method is called.C LanguageThread sleep function.

Attaches the method to the object, and the method signature is sleep (); No parameter. The default sleep is 1 second. If you call this function in JS, the browser UI interface will be blocked.

In addition, if your JS function has an endless loop, the browser's Js parsing will detect JS execution timeout and remind you whether to terminate the execution of JS on this page.

Finally, a newly compiled JS engine is provided. replace them with the JS engine in Firefox.

Then you can write a piece of Js for fun, such as "testsleep". Sleep (); because I added it to an object, you can call this function on any JS object.

Attachment: firefox_js.rar
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.