The difference between the first parameter of setInterval () with quotation marks and without quotation marks is that of setinterval quotation marks.

Source: Internet
Author: User

The difference between the first parameter of setInterval () with quotation marks and without quotation marks is that of setinterval quotation marks.

The difference between the first parameter of setInterval () with and without quotation marks:
The basic usage of the timer function setInterval () is not introduced here. Please refer to the relevant tutorials. Here we will mainly introduce setInterval () the first parameter of the function is different in two different forms and should be paid attention to in the application. The following is a brief introduction based on the instance.
The first parameter of the setInterval () function has two forms:
I. string format:

setInterval("a()",1000)

Ii. pointer format:

setInterval(a,1000);

Both of the preceding methods are frequently used, and the () function can be executed every second. However, the two methods do not take effect in all cases.
The code example is as follows:

<! DOCTYPE html> 

The above Code does not achieve the expected effect, that is, the number auto-increment phenomenon in the div, it seems that the Code is not wrong. Let's look at a code example:

<! DOCTYPE html> 

The code above realizes the auto-Increment Effect of numbers in the div. If two instance codes are compared, the only difference is that the first parameter of the setInterval () function is different. The first parameter is a string, and the second parameter is a pointer. The two differences are described below:
1. When it is a string:
When the parameter is a string, the "addNumber" parameter passed by the function has no relationship with the addNumber function at all, and the setInterval () function processes the string in a way similar to the eval () function, the addNumber () function will be searched in the global scope, so the addNumber is not defined error will appear. This method has the same eval () problem, so it is not recommended.
2. When the function name is used:
When the parameter is a function name, the pointer of the addNumber () function actually passed (that is, the address of the function's storage), and because the addNumber () function is declared in scope B, the setInterval () function is also used in scope B, so the addNumber () function can be found. For more information about scopes, see section 1 about javascript scopes and scopes.

The original address is: http://www.softwhy.com/forum.php? Mod = viewthread & tid = 6327.

For more information, see: http://www.softwhy.com/javascript/

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.