SetTimeout, Cleartimeout, setinterval

Source: Internet
Author: User

SetTimeout (CB, MS)

The setTimeout (CB, MS) global function executes the specified function (CB) After the specified number of milliseconds (ms). : SetTimeout () executes the specified function only once.

Returns a handle value representing the timer.

Instance

To create the file main.js, the code looks like this:

functionPrinthello(){Console.Log("Hello, world!.");}///After two seconds to execute the above functionSetTimeout(Printhello, -);

Execute the main.js file, as shown in the following code:

$ node Main . JS Hello ,  World !
Cleartimeout (t)

The cleartimeout (t) global function is used to stop a timer that was previously created by SetTimeout (). The parameter T is a timer created by the SetTimeout () function.

Instance

To create the file main.js, the code looks like this:

functionPrinthello(){Console.Log("Hello, world!.");}///After two seconds to execute the above functionvarT=SetTimeout(Printhello, -);//Clear Timercleartimeout(T);

Execute the main.js file, as shown in the following code:

$ node Main . JS
SetInterval (CB, MS)

The setinterval (CB, MS) global function executes the specified function (CB) After the specified number of milliseconds (ms).

Returns a handle value representing the timer. You can use the clearinterval (t) function to clear the timer.

The SetInterval () method keeps calling functions until Clearinterval () is called or the window is closed.

Instance

To create the file main.js, the code looks like this:

functionPrinthello(){Console.Log("Hello, world!.");}///After two seconds to execute the above functionsetinterval(Printhello, -);

Execute the main.js file, as shown in the following code:

$ node Main . JS

Hello, world!. Hello, world!. Hello, world!. Hello, world!. Hello, world!. ......

The above program will output "Hello, world!" every two seconds, and will be executed permanently until you press CTRL + C button.

SetTimeout, Cleartimeout, setinterval

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.