Javascript Modular programming-immediate execution of functions (IIFE), javascriptiife

Source: Internet
Author: User

Javascript Modular programming-immediate execution of functions (IIFE), javascriptiife
IIFE

Fully spell Imdiately Invoked Function Expression, the Function Expression to be executed immediately.

Syntax
Var module1 = (function () {var _ count = 0; var m1 = function (){//...}; var m2 = function (){//...}; return {m1: m1, m2: m2 };})();

Using the above Code, external code cannot read the internal _ count variable.

Meaning of parentheses

1,WrapFunction (){}Meaning of brackets

The purpose of the parentheses isFunction (){}Convert to an expression. Easy to execute. If this bracket is removed, an error is returned. Because simpleFunction (){}If it is not an executable expression, an error is reported.

2,Meaning of the second bracket

Explain understands the meaning of the first bracket. The second bracket is simple, that is, the execution expression.

Reference
$ (Fuction () {module1.m1 (); // call m1 ;});

 

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.