Win8: anonymous functions and strict Mode

Source: Internet
Author: User

CodeAs follows:

(Function(){"Use strict ";//Declares strict mode....})();

Anonymous function reason:

Javascript has two scopes: global and local. If a variable is declared outside the definition of any function, the variable is a global variable andProgramYou can access and modify the value of this variable. If a variable is declared in a function definition, the variable is a local variable. NO content except this function can access this variable.

Code wrapped in anonymous functions can make the code private. Packaging code in anonymous functions is a good coding practice, because this can limit the scope of the code and avoid damage to the global namespace. In this way, you can avoid name conflicts or accidentally modify a value.

Although JavaScript does not support private members, you can use anonymous functions to create private members when using JavaScript encoding.

The extra parentheses at the end of the function declaration are used to call anonymous functions.

Strict mode:

Strict mode can provide better error checking for JavaScript code. When the strict mode is used, the code is more restrictive than that allowed by JavaScript normally.

For more limits, see: http://msdn.microsoft.com/zh-cn/library/windows/apps/br230269.aspx

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.