Precautions for using setTimeout in js, jssettimeout

Source: Internet
Author: User

Precautions for using setTimeout in js, jssettimeout

SetTimeout is frequently used in js. The most common is timer.

SetTimeout usage is simple var r = setTimeout (func, 1000 );

First, it uses the return value to clear setTimeout and clearTimeout (r)

SetTimeout call Method

SetTimeout (func, 1000 );

SetTimeout ("func ()", 1000 );

SetTimeout (function () {func ()}, 1000 );


In the first method, note that this points to the problem.

Var A = function ()

{

This. key = 1;

This. valuesss = 1;

This. func = function ()

{

Alert (this. valuesss );

}

}

Var a = new ();

SetTimeout (a. func, 1000 );

At this time, the system will surely prompt that the valuesss cannot be found, because this points to the window

Window. setTimeout = function (func, timer ){}

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.