Home >Web Front-end >JS Tutorial >Provide sleep function (sleep) for JavaScript Self-compiled JS engine_javascript skills

Provide sleep function (sleep) for JavaScript Self-compiled JS engine_javascript skills

WBOY
WBOYOriginal
2016-05-16 18:21:061369browse

Since this function is so needed, why does js not provide such a function?

Currently, browsers parse js in the UI thread. Taking Firefox as an example, I recompiled the js engine, and The sleep method is added to the js alert, which calls the thread sleep function of the c language.
Attach the method to the Object, the method signature is sleep(); no parameters. The default sleep is 1 second, if you are in js When this function is called, the browser UI interface will be blocked.


In addition, if there is an infinite loop in your js function, the browser's js parsing will detect the js execution timeout and remind you whether to terminate the execution of the js on this page.
Finally provide the newly compiled js Engine, just replace them with the js engine under firefox.

Then you can write a piece of js to play with, such as "testSleep".sleep(); because I added it in Object, so you can Call this function on any js object.

Instructions for use:
Mainly requires website visitors to install your customized browser.
You can just publish the Firefox client yourself, if your project really needs it.
We must specify our own browser, which is as simple as requiring users to install the flash plug-in.

Attachment: firefox_js.rar

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn